• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP entity_revision_load函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中entity_revision_load函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_revision_load函数的具体用法?PHP entity_revision_load怎么用?PHP entity_revision_load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了entity_revision_load函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: testRevisions

 /**
  * Checks block revision related operations.
  */
 public function testRevisions()
 {
     $blocks = $this->blocks;
     $logs = $this->revisionLogs;
     foreach ($blocks as $delta => $revision_id) {
         // Confirm the correct revision text appears.
         $loaded = entity_revision_load('block_content', $revision_id);
         // Verify revision log is the same.
         $this->assertEqual($loaded->getRevisionLog(), $logs[$delta], format_string('Correct log message found for revision !revision', array('!revision' => $loaded->getRevisionId())));
     }
     // Confirm that this is the default revision.
     $this->assertTrue($loaded->isDefaultRevision(), 'Third block revision is the default one.');
     // Make a new revision and set it to not be default.
     // This will create a new revision that is not "front facing".
     // Save this as a non-default revision.
     $loaded->setNewRevision();
     $loaded->isDefaultRevision(FALSE);
     $loaded->body = $this->randomMachineName(8);
     $loaded->save();
     $this->drupalGet('block/' . $loaded->id());
     $this->assertNoText($loaded->body->value, 'Revision body text is not present on default version of block.');
     // Verify that the non-default revision id is greater than the default
     // revision id.
     $default_revision = entity_load('block_content', $loaded->id());
     $this->assertTrue($loaded->getRevisionId() > $default_revision->getRevisionId(), 'Revision id is greater than default revision id.');
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:BlockContentRevisionsTest.php


示例2: prepareView

 /**
  * {@inheritdoc}
  *
  * Mark the accessible IDs a user can see. We do not unset unaccessible
  * values, as other may want to act on those values, even if they can
  * not be accessed.
  */
 public function prepareView(array $entities_items)
 {
     $target_ids = array();
     $revision_ids = array();
     // Collect every possible entity attached to any of the entities.
     foreach ($entities_items as $items) {
         foreach ($items as $item) {
             if (!empty($item->revision_id)) {
                 $revision_ids[] = $item->revision_id;
             } elseif (!empty($item->target_id)) {
                 $target_ids[] = $item->target_id;
             }
         }
     }
     $target_type = $this->getFieldSetting('target_type');
     $target_entities = array();
     if ($target_ids) {
         $target_entities = entity_load_multiple($target_type, $target_ids);
     }
     if ($revision_ids) {
         // We need to load the revisions one by-one.
         foreach ($revision_ids as $revision_id) {
             $target_entity = entity_revision_load($target_type, $revision_id);
             // Use the revision ID in the key.
             $identifier = $target_entity->id() . ':' . $revision_id;
             $target_entities[$identifier] = $target_entity;
         }
     }
     // Iterate through the fieldable entities again to attach the loaded data.
     foreach ($entities_items as $items) {
         $rekey = FALSE;
         foreach ($items as $item) {
             // If we have a revision ID, the key uses it as well.
             $identifier = !empty($item->revision_id) ? $item->target_id . ':' . $item->revision_id : $item->target_id;
             if ($item->target_id !== 0) {
                 if (!isset($target_entities[$identifier])) {
                     // The entity no longer exists, so empty the item.
                     $item->setValue(NULL);
                     $rekey = TRUE;
                     continue;
                 }
                 $item->entity = $target_entities[$identifier];
                 if (!$item->entity->access('view')) {
                     continue;
                 }
             } else {
                 // This is an "auto_create" item, just leave the entity in place.
             }
             // Mark item as accessible.
             $item->access = TRUE;
         }
         // Rekey the items array if needed.
         if ($rekey) {
             $items->filterEmptyItems();
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:64,代码来源:EntityReferenceFormatterBase.php


示例3: getTarget

 /**
  * {@inheritdoc}
  */
 public function getTarget()
 {
     if (!isset($this->target) && isset($this->revision_id)) {
         // If we have a valid reference, return the entity's TypedData adapter.
         $entity = entity_revision_load($this->getTargetDefinition()->getEntityTypeId(), $this->revision_id);
         $this->target = isset($entity) ? $entity->getTypedData() : NULL;
     }
     return $this->target;
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:12,代码来源:EntityReferenceRevisions.php


示例4: runRevisionsTests

 /**
  * Executes the revision tests for the given entity type.
  *
  * @param string $entity_type
  *   The entity type to run the tests with.
  */
 protected function runRevisionsTests($entity_type)
 {
     // Create initial entity.
     $entity = $this->container->get('entity_type.manager')->getStorage($entity_type)->create(array('name' => 'foo', 'user_id' => $this->webUser->id()));
     $entity->field_test_text->value = 'bar';
     $entity->save();
     $names = array();
     $texts = array();
     $created = array();
     $revision_ids = array();
     // Create three revisions.
     $revision_count = 3;
     for ($i = 0; $i < $revision_count; $i++) {
         $legacy_revision_id = $entity->revision_id->value;
         $legacy_name = $entity->name->value;
         $legacy_text = $entity->field_test_text->value;
         $entity = entity_load($entity_type, $entity->id->value);
         $entity->setNewRevision(TRUE);
         $names[] = $entity->name->value = $this->randomMachineName(32);
         $texts[] = $entity->field_test_text->value = $this->randomMachineName(32);
         $created[] = $entity->created->value = time() + $i + 1;
         $entity->save();
         $revision_ids[] = $entity->revision_id->value;
         // Check that the fields and properties contain new content.
         $this->assertTrue($entity->revision_id->value > $legacy_revision_id, format_string('%entity_type: Revision ID changed.', array('%entity_type' => $entity_type)));
         $this->assertNotEqual($entity->name->value, $legacy_name, format_string('%entity_type: Name changed.', array('%entity_type' => $entity_type)));
         $this->assertNotEqual($entity->field_test_text->value, $legacy_text, format_string('%entity_type: Text changed.', array('%entity_type' => $entity_type)));
     }
     for ($i = 0; $i < $revision_count; $i++) {
         // Load specific revision.
         $entity_revision = entity_revision_load($entity_type, $revision_ids[$i]);
         // Check if properties and fields contain the revision specific content.
         $this->assertEqual($entity_revision->revision_id->value, $revision_ids[$i], format_string('%entity_type: Revision ID matches.', array('%entity_type' => $entity_type)));
         $this->assertEqual($entity_revision->name->value, $names[$i], format_string('%entity_type: Name matches.', array('%entity_type' => $entity_type)));
         $this->assertEqual($entity_revision->field_test_text->value, $texts[$i], format_string('%entity_type: Text matches.', array('%entity_type' => $entity_type)));
         // Check non-revisioned values are loaded.
         $this->assertTrue(isset($entity_revision->created->value), format_string('%entity_type: Non-revisioned field is loaded.', array('%entity_type' => $entity_type)));
         $this->assertEqual($entity_revision->created->value, $created[2], format_string('%entity_type: Non-revisioned field value is the same between revisions.', array('%entity_type' => $entity_type)));
     }
     // Confirm the correct revision text appears in the edit form.
     $entity = entity_load($entity_type, $entity->id->value);
     $this->drupalGet($entity_type . '/manage/' . $entity->id->value . '/edit');
     $this->assertFieldById('edit-name-0-value', $entity->name->value, format_string('%entity_type: Name matches in UI.', array('%entity_type' => $entity_type)));
     $this->assertFieldById('edit-field-test-text-0-value', $entity->field_test_text->value, format_string('%entity_type: Text matches in UI.', array('%entity_type' => $entity_type)));
 }
开发者ID:318io,项目名称:318-io,代码行数:51,代码来源:EntityRevisionsTest.php


示例5: mos_field_collection_nested_values

/**
 * fix to get values from nested field collections nested in other field collections 
 *
 * @param string[] $fields is an array of strings that represents the levels of the nest - so array('content_column', 'column_title') woud be for content title in content column
 * @param mixed[] $collection is a...it's "drupal magic" which is more like drupal voodoo and the tpls are the pin-cusion dolls linked to your soul and every time you hack them it causes physical pain
 * @param string $value is a bunch of who-cares
 * @param mixed $default is null - recently a stackoverflow.com survey listed back-end web devs as the least satisfied with their jobs that is not a joke but right now is making it sad and funny at the same time
 * @return mixed[]
 */
function mos_field_collection_nested_values($fields, $collection, $value = 'value', $default = null)
{
    $collection = mos_array_first($collection['entity']['field_collection_item']);
    $values = array();
    $collections = array();
    $fields = array_values($fields);
    foreach ($fields as $key => $field) {
        $fields[$key] = 'field_' . mos_preg_remove('/^field_/', $field);
    }
    foreach (mos_array_get(mos_array_get($collection, $fields[0], array()), '#items', array()) as $item) {
        //$collections[] = mos_array_first(mos_object_to_array(entity_load('field_collection_item', array($item['value']))));
        $collections[] = mos_object_to_array(entity_revision_load('field_collection_item', $item['revision_id']));
    }
    foreach ($collections as $key => $collection) {
        $values[$key] = array();
        foreach (mos_array_get(mos_array_get($collection, $fields[1], $default), 'und', array()) as $key2 => $nested) {
            $values[$key][$key2] = $nested[$value];
        }
    }
    return $values;
}
开发者ID:bonniebo421,项目名称:subsites,代码行数:30,代码来源:template-functions.php


示例6: loadEntities

  /**
   * Loads all entities contained in the passed-in $results.
   *.
   * If the entity belongs to the base table, then it gets stored in
   * $result->_entity. Otherwise, it gets stored in
   * $result->_relationship_entities[$relationship_id];
   *
   * @param \Drupal\views\ResultRow[] $results
   *   The result of the SQL query.
   */
  public function loadEntities(&$results) {
    $entity_information = $this->getEntityTableInfo();
    // No entity tables found, nothing else to do here.
    if (empty($entity_information)) {
      return;
    }

    // Extract all entity types from entity_information.
    $entity_types = array();
    foreach ($entity_information as $info) {
      $entity_type = $info['entity_type'];
      if (!isset($entity_types[$entity_type])) {
        $entity_types[$entity_type] = \Drupal::entityManager()->getDefinition($entity_type);
      }
    }

    // Assemble a list of entities to load.
    $ids_by_type = array();
    foreach ($entity_information as $info) {
      $relationship_id = $info['relationship_id'];
      $entity_type = $info['entity_type'];
      $entity_info = $entity_types[$entity_type];
      $id_key = !$info['revision'] ? $entity_info->getKey('id') : $entity_info->getKey('revision');
      $id_alias = $this->getFieldAlias($info['alias'], $id_key);

      foreach ($results as $index => $result) {
        // Store the entity id if it was found.
        if (isset($result->{$id_alias}) && $result->{$id_alias} != '') {
          $ids_by_type[$entity_type][$index][$relationship_id] = $result->$id_alias;
        }
      }
    }

    // Load all entities and assign them to the correct result row.
    foreach ($ids_by_type as $entity_type => $ids) {
      $flat_ids = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($ids)), FALSE);

      // Drupal core currently has no way to load multiple revisions. Sad.
      if (isset($entity_information[$entity_type]['revision']) && $entity_information[$entity_type]['revision'] === TRUE) {
        $entities = array();
        foreach ($flat_ids as $revision_id) {
          $entity = entity_revision_load($entity_type, $revision_id);
          if ($entity) {
            $entities[$revision_id] = $entity;
          }
        }
      }
      else {
        $entities = entity_load_multiple($entity_type, $flat_ids);
      }

      foreach ($ids as $index => $relationships) {
        foreach ($relationships as $relationship_id => $entity_id) {
          if (isset($entities[$entity_id])) {
            $entity = $entities[$entity_id];
          }
          else {
            $entity = NULL;
          }

          if ($relationship_id == 'none') {
            $results[$index]->_entity = $entity;
          }
          else {
            $results[$index]->_relationship_entities[$relationship_id] = $entity;
          }
        }
      }
    }
  }
开发者ID:jthoresen,项目名称:PladsenDrupal,代码行数:80,代码来源:Sql.php


示例7: loadEntities

 /**
  * Loads all entities contained in the passed-in $results.
  *.
  * If the entity belongs to the base table, then it gets stored in
  * $result->_entity. Otherwise, it gets stored in
  * $result->_relationship_entities[$relationship_id];
  */
 function loadEntities(&$results)
 {
     $entity_information = $this->getEntityTableInfo();
     // No entity tables found, nothing else to do here.
     if (empty($entity_information)) {
         return;
     }
     // Assemble a list of entities to load.
     $ids_by_type = array();
     foreach ($entity_information as $entity_type => $info) {
         $entity_info = \Drupal::entityManager()->getDefinition($entity_type);
         $id_key = empty($table['revision']) ? $entity_info->getKey('id') : $entity_info->getKey('revision');
         $id_alias = $this->getFieldAlias($info['alias'], $id_key);
         foreach ($results as $index => $result) {
             // Store the entity id if it was found.
             if (isset($result->{$id_alias}) && $result->{$id_alias} != '') {
                 $ids_by_type[$entity_type][$index] = $result->{$id_alias};
             }
         }
     }
     // Load all entities and assign them to the correct result row.
     foreach ($ids_by_type as $entity_type => $ids) {
         $info = $entity_information[$entity_type];
         $relationship_id = $info['relationship_id'];
         // Drupal core currently has no way to load multiple revisions. Sad.
         if ($info['revision']) {
             $entities = array();
             foreach ($ids as $revision_id) {
                 $entity = entity_revision_load($entity_type, $revision_id);
                 if ($entity) {
                     $entities[$revision_id] = $entity;
                 }
             }
         } else {
             $entities = entity_load_multiple($entity_type, $ids);
         }
         foreach ($ids as $index => $id) {
             if (isset($entities[$id])) {
                 $entity = $entities[$id];
             } else {
                 $entity = NULL;
             }
             if ($relationship_id == 'none') {
                 $results[$index]->_entity = $entity;
             } else {
                 $results[$index]->_relationship_entities[$relationship_id] = $entity;
             }
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:57,代码来源:Sql.php


示例8: checkTranslationRevisions

 /**
  * Check if the field translation attached to the entity revision identified
  * by the passed arguments were correctly stored.
  */
 private function checkTranslationRevisions($id, $revision_id, $available_langcodes)
 {
     $field_name = $this->fieldStorage->getName();
     $entity = entity_revision_load($this->entityTypeId, $revision_id);
     foreach ($available_langcodes as $langcode => $value) {
         $passed = $entity->getTranslation($langcode)->{$field_name}->value == $value + 1;
         $this->assertTrue($passed, format_string('The @language translation for revision @revision was correctly stored', array('@language' => $langcode, '@revision' => $entity->getRevisionId())));
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:13,代码来源:TranslationWebTest.php


示例9: setRevision

 public function setRevision($revision_id)
 {
     $revision = \entity_revision_load($this->type(), $revision_id);
     if (!$revision) {
         return false;
     }
     $this->definition = $revision;
     return true;
 }
开发者ID:sammarks,项目名称:publisher,代码行数:9,代码来源:Entity.php



注:本文中的entity_revision_load函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP entity_test_create_bundle函数代码示例发布时间:2022-05-15
下一篇:
PHP entity_metadata_wrapper函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap