closedquestion-8.x-3.x-dev/src/Menu/ClosedQuestionCollectionLocalActionProvider.php

src/Menu/ClosedQuestionCollectionLocalActionProvider.php
<?php

namespace Drupal\closedquestion\Menu;

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\entity\Menu\EntityCollectionLocalActionProvider;

/**
 * Provides a action link to the add page or add form on the collection.
 */
class ClosedQuestionCollectionLocalActionProvider extends EntityCollectionLocalActionProvider {

  /**
   * {@inheritdoc}
   */
  public function buildLocalActions(EntityTypeInterface $entity_type) {
    $actions = [];
    if ($entity_type->hasLinkTemplate('collection')) {
      $entity_type_id = $entity_type->id();

      if ($entity_type->hasLinkTemplate('add-form')) {
        $route_name = "entity.$entity_type_id.add_form";
      }

      if (isset($route_name)) {
        $actions[$route_name] = [
          'title' => $this->t('Add @entity', [
            '@entity' => $entity_type->getSingularLabel(),
          ]),
          'route_name' => $route_name,
          'appears_on' => ["entity.$entity_type_id.collection"],
        ];
      }
    }
    return $actions;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc