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


PHP EntityInterface::setNewRevision方法代码示例

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


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

示例1: save

 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     // Save as a new revision if requested to do so.
     if (!$form_state->isValueEmpty('revision')) {
         $this->entity->setNewRevision();
     }
     $insert = $this->entity->isNew();
     $this->entity->save();
     $context = ['@type' => $this->entity->bundle(), '%info' => $this->entity->label()];
     $logger = $this->logger($this->entity->id());
     $bundle_entity = $this->getBundleEntity();
     $t_args = ['@type' => $bundle_entity ? $bundle_entity->label() : 'None', '%info' => $this->entity->label()];
     if ($insert) {
         $logger->notice('@type: added %info.', $context);
         drupal_set_message($this->t('@type %info has been created.', $t_args));
     } else {
         $logger->notice('@type: updated %info.', $context);
         drupal_set_message($this->t('@type %info has been updated.', $t_args));
     }
     if ($this->entity->id()) {
         $form_state->setValue('id', $this->entity->id());
         $form_state->set('id', $this->entity->id());
         if ($this->entity->getEntityType()->hasLinkTemplate('collection')) {
             $form_state->setRedirectUrl($this->entity->toUrl('collection'));
         } else {
             $form_state->setRedirectUrl($this->entity->toUrl('canonical'));
         }
     } else {
         // In the unlikely case something went wrong on save, the entity will be
         // rebuilt and entity form redisplayed.
         drupal_set_message($this->t('The entity could not be saved.'), 'error');
         $form_state->setRebuild();
     }
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:37,代码来源:RevisionableContentEntityForm.php

示例2: init

 /**
  * Initialize the form state and the entity before the first form build.
  */
 protected function init(FormStateInterface $form_state, EntityInterface $entity, $field_name)
 {
     // @todo Rather than special-casing $node->revision, invoke prepareEdit()
     //   once https://www.drupal.org/node/1863258 lands.
     if ($entity->getEntityTypeId() == 'node') {
         $node_type = $this->nodeTypeStorage->load($entity->bundle());
         $entity->setNewRevision($node_type->isNewRevision());
         $entity->revision_log = NULL;
     }
     $form_state->set('entity', $entity);
     $form_state->set('field_name', $field_name);
     // Fetch the display used by the form. It is the display for the 'default'
     // form mode, with only the current field visible.
     $display = EntityFormDisplay::collectRenderDisplay($entity, 'default');
     foreach ($display->getComponents() as $name => $options) {
         if ($name != $field_name) {
             $display->removeComponent($name);
         }
     }
     $form_state->set('form_display', $display);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:24,代码来源:QuickEditFieldForm.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: init

 /**
  * Initialize the form state and the entity before the first form build.
  */
 protected function init(array &$form_state, EntityInterface $entity, $field_name)
 {
     // @todo Rather than special-casing $node->revision, invoke prepareEdit()
     //   once http://drupal.org/node/1863258 lands.
     if ($entity->getEntityTypeId() == 'node') {
         $node_type_settings = $this->nodeTypeStorage->load($entity->bundle())->getModuleSettings('node');
         $options = isset($node_type_settings['options']) ? $node_type_settings['options'] : array();
         $entity->setNewRevision(!empty($options['revision']));
         $entity->revision_log = NULL;
     }
     $form_state['entity'] = $entity;
     $form_state['field_name'] = $field_name;
     // Fetch the display used by the form. It is the display for the 'default'
     // form mode, with only the current field visible.
     $display = EntityFormDisplay::collectRenderDisplay($entity, 'default');
     foreach ($display->getComponents() as $name => $optipns) {
         if ($name != $field_name) {
             $display->removeComponent($name);
         }
     }
     $form_state['form_display'] = $display;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:25,代码来源:QuickEditFieldForm.php

示例5: 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::setNewRevision方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。