当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityInterface::isDefaultRevision方法代码示例

本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::isDefaultRevision方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::isDefaultRevision方法的具体用法?PHP EntityInterface::isDefaultRevision怎么用?PHP EntityInterface::isDefaultRevision使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Entity\EntityInterface的用法示例。


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

示例1: alterBuild

 /**
  * {@inheritdoc}
  */
 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
 {
     $entity_type_id = $entity->getEntityTypeId();
     if ($entity instanceof ContentEntityInterface && $entity->isDefaultRevision() || !$entity->getEntityType()->isRevisionable()) {
         $build['#contextual_links'][$entity_type_id] = ['route_parameters' => [$entity_type_id => $entity->id()]];
     } else {
         $build['#contextual_links'][$entity_type_id . '_revision'] = ['route_parameters' => [$entity_type_id => $entity->id(), $entity_type_id . '_revision' => $entity->getRevisionId()]];
     }
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:12,代码来源:EntityViewBuilder.php

示例2: saveFieldItems

 /**
  * Saves values of configurable fields for an entity.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity.
  * @param bool $update
  *   TRUE if the entity is being updated, FALSE if it is being inserted.
  */
 protected function saveFieldItems(EntityInterface $entity, $update = TRUE)
 {
     $vid = $entity->getRevisionId();
     $id = $entity->id();
     $bundle = $entity->bundle();
     $entity_type = $entity->getEntityTypeId();
     $default_langcode = $entity->getUntranslated()->language()->id;
     $translation_langcodes = array_keys($entity->getTranslationLanguages());
     if (!isset($vid)) {
         $vid = $id;
     }
     foreach ($this->entityManager->getFieldDefinitions($entity_type, $bundle) as $field_name => $field_definition) {
         $storage_definition = $field_definition->getFieldStorageDefinition();
         if (!$this->usesDedicatedTable($storage_definition)) {
             continue;
         }
         $table_name = static::_fieldTableName($storage_definition);
         $revision_name = static::_fieldRevisionTableName($storage_definition);
         // Delete and insert, rather than update, in case a value was added.
         if ($update) {
             // Only overwrite the field's base table if saving the default revision
             // of an entity.
             if ($entity->isDefaultRevision()) {
                 $this->database->delete($table_name)->condition('entity_id', $id)->execute();
             }
             $this->database->delete($revision_name)->condition('entity_id', $id)->condition('revision_id', $vid)->execute();
         }
         // Prepare the multi-insert query.
         $do_insert = FALSE;
         $columns = array('entity_id', 'revision_id', 'bundle', 'delta', 'langcode');
         foreach ($storage_definition->getColumns() as $column => $attributes) {
             $columns[] = static::_fieldColumnName($storage_definition, $column);
         }
         $query = $this->database->insert($table_name)->fields($columns);
         $revision_query = $this->database->insert($revision_name)->fields($columns);
         $langcodes = $field_definition->isTranslatable() ? $translation_langcodes : array($default_langcode);
         foreach ($langcodes as $langcode) {
             $delta_count = 0;
             $items = $entity->getTranslation($langcode)->get($field_name);
             $items->filterEmptyItems();
             foreach ($items as $delta => $item) {
                 // We now know we have someting to insert.
                 $do_insert = TRUE;
                 $record = array('entity_id' => $id, 'revision_id' => $vid, 'bundle' => $bundle, 'delta' => $delta, 'langcode' => $langcode);
                 foreach ($storage_definition->getColumns() as $column => $attributes) {
                     $column_name = static::_fieldColumnName($storage_definition, $column);
                     // Serialize the value if specified in the column schema.
                     $record[$column_name] = !empty($attributes['serialize']) ? serialize($item->{$column}) : $item->{$column};
                 }
                 $query->values($record);
                 $revision_query->values($record);
                 if ($storage_definition->getCardinality() != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && ++$delta_count == $storage_definition->getCardinality()) {
                     break;
                 }
             }
         }
         // Execute the query if we have values to insert.
         if ($do_insert) {
             // Only overwrite the field's base table if saving the default revision
             // of an entity.
             if ($entity->isDefaultRevision()) {
                 $query->execute();
             }
             $revision_query->execute();
         }
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:75,代码来源:ContentEntityDatabaseStorage.php

示例3: doSave

 /**
  * {@inheritdoc}
  */
 protected function doSave($id, EntityInterface $entity)
 {
     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     if ($entity->isNew()) {
         // Ensure the entity is still seen as new after assigning it an id, while
         // storing its data.
         $entity->enforceIsNew();
         if ($this->entityType->isRevisionable()) {
             $entity->setNewRevision();
         }
         $return = SAVED_NEW;
     } else {
         // @todo Consider returning a different value when saving a non-default
         //   entity revision. See https://www.drupal.org/node/2509360.
         $return = $entity->isDefaultRevision() ? SAVED_UPDATED : FALSE;
     }
     $this->populateAffectedRevisionTranslations($entity);
     $this->doSaveFieldItems($entity);
     return $return;
 }
开发者ID:Progressable,项目名称:openway8,代码行数:23,代码来源:ContentEntityStorageBase.php

示例4: doSave

 /**
  * {@inheritdoc}
  *
  * @todo Revisit this logic with forward revisions in mind.
  */
 protected function doSave($id, EntityInterface $entity)
 {
     if ($entity->_rev->is_stub) {
         $entity->isDefaultRevision(TRUE);
     } else {
         // Enforce new revision if any module messed with it in a hook.
         $entity->setNewRevision();
         // Decide whether or not this is the default revision.
         if (!$entity->isNew()) {
             $default_rev = \Drupal::service('entity.index.rev.tree')->getDefaultRevision($entity->uuid());
             if ($entity->_rev->value == $default_rev) {
                 $entity->isDefaultRevision(TRUE);
             } else {
                 $entity->isDefaultRevision(FALSE);
             }
         }
     }
     return parent::doSave($id, $entity);
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:24,代码来源:ContentEntityStorageTrait.php


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