コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $this->derivatives = [];
     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
         if ($this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) {
             $bundle_id = $entity_type->getBundleEntityType();
             $this->derivatives["{$bundle_id}.moderation_tab"] = ['route_name' => "entity.{$bundle_id}.moderation", 'title' => $this->t('Manage moderation'), 'base_route' => "entity.{$bundle_id}.edit_form", 'weight' => 30] + $base_plugin_definition;
         }
     }
     $latest_version_entities = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $type) {
         return $this->moderationInfo->canModerateEntitiesOfEntityType($type) && $type->hasLinkTemplate('latest-version');
     });
     foreach ($latest_version_entities as $entity_type_id => $entity_type) {
         $this->derivatives["{$entity_type_id}.latest_version_tab"] = ['route_name' => "entity.{$entity_type_id}.latest_version", 'title' => $this->t('Latest version'), 'base_route' => "entity.{$entity_type_id}.canonical", 'weight' => 1] + $base_plugin_definition;
     }
     return $this->derivatives;
 }
コード例 #2
0
ファイル: ViewsData.php プロジェクト: eigentor/tommiblog
 /**
  * Alters the table and field information from hook_views_data().
  *
  * @param array $data
  *   An array of all information about Views tables and fields, collected from
  *   hook_views_data(), passed by reference.
  *
  * @see hook_views_data()
  */
 public function alterViewsData(array &$data)
 {
     $entity_types_with_moderation = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $type) {
         return $this->moderationInformation->canModerateEntitiesOfEntityType($type);
     });
     foreach ($entity_types_with_moderation as $type) {
         $data[$type->getRevisionTable()]['latest_revision'] = ['title' => t('Is Latest Revision'), 'help' => t('Restrict the view to only revisions that are the latest revision of their entity.'), 'filter' => ['id' => 'latest_revision']];
     }
 }
コード例 #3
0
ファイル: EntityTypeInfo.php プロジェクト: eigentor/tommiblog
 /**
  * Alters bundle forms to enforce revision handling.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param string $form_id
  *   The form id.
  *
  * @see hook_form_alter()
  */
 public function formAlter(array &$form, FormStateInterface $form_state, $form_id)
 {
     $form_object = $form_state->getFormObject();
     if ($form_object instanceof BundleEntityFormBase) {
         $type = $form_object->getEntity()->getEntityType();
         if ($this->moderationInfo->canModerateEntitiesOfEntityType($type)) {
             $this->entityTypeManager->getHandler($type->getBundleOf(), 'moderation')->enforceRevisionsBundleFormAlter($form, $form_state, $form_id);
         }
     } elseif ($form_object instanceof ContentEntityFormInterface) {
         $entity = $form_object->getEntity();
         if ($this->moderationInfo->isModeratedEntity($entity)) {
             $this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->enforceRevisionsEntityFormAlter($form, $form_state, $form_id);
             // Submit handler to redirect to the latest version, if available.
             $form['actions']['submit']['#submit'][] = [EntityTypeInfo::class, 'bundleFormRedirect'];
         }
     }
 }