getDefaultOperations example

/** * Defines a class to build a listing of block type entities. * * @see \Drupal\block_content\Entity\BlockContentType */
class BlockContentTypeListBuilder extends ConfigEntityListBuilder {

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);
    // Place the edit operation after the operations added by field_ui.module     // which have the weights 15, 20, 25.     if (isset($operations['edit'])) {
      $operations['edit']['weight'] = 30;
    }
    return $operations;
  }

  /** * {@inheritdoc} */
  
'#attributes' => [
          'class' => ['views-ui-operations'],
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);
    // Remove destination redirect for Edit operation.     $operations['edit']['url'] = $entity->toUrl('edit-form');

    if ($entity->hasLinkTemplate('duplicate-form')) {
      $operations['duplicate'] = [
        'title' => $this->t('Duplicate'),
        'weight' => 15,
        'url' => $entity->toUrl('duplicate-form'),
      ];
    }

    
'#button_type' => 'primary',
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    /** @var \Drupal\search\SearchPageInterface $entity */
    $operations = parent::getDefaultOperations($entity);

    // Prevent the default search from being disabled or deleted.     if ($entity->isDefaultSearch()) {
      unset($operations['disable']$operations['delete']);
    }
    else {
      $operations['default'] = [
        'title' => $this->t('Set as default'),
        'url' => Url::fromRoute('entity.search_page.set_default', [
          'search_page' => $entity->id(),
        ]),
        

  public function buildHeader() {
    $header['name'] = t('Name');
    return $header + parent::buildHeader();
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);

    if (isset($operations['edit'])) {
      $operations['edit']['title'] = t('Edit shortcut set');
    }

    $operations['list'] = [
      'title' => t('List links'),
      'url' => $entity->toUrl('customize-form'),
    ];
    return $operations;
  }

  
// Sort the entities using the entity class's sort() method.     // See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().     uasort($entities[$this->entityType->getClass(), 'sort']);
    return $entities;
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    $operations = parent::getDefaultOperations($entity);

    if ($this->entityType->hasKey('status')) {
      if (!$entity->status() && $entity->hasLinkTemplate('enable')) {
        $operations['enable'] = [
          'title' => t('Enable'),
          'weight' => -10,
          'url' => $this->ensureDestination($entity->toUrl('enable')),
        ];
      }
      elseif ($entity->hasLinkTemplate('disable')) {
        $operations['disable'] = [
          

  public function buildRow(EntityInterface $entity) {
    $row['label'] = $entity->label();
    return $row + parent::buildRow($entity);
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);

    if ($entity->hasLinkTemplate('edit-permissions-form')) {
      $operations['permissions'] = [
        'title' => t('Edit permissions'),
        'weight' => 20,
        'url' => $entity->toUrl('edit-permissions-form'),
      ];
    }
    return $operations;
  }

  
/** * {@inheritdoc} */
  public function getFormId() {
    return 'taxonomy_overview_vocabularies';
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);

    if (isset($operations['edit'])) {
      $operations['edit']['title'] = t('Edit vocabulary');
    }
    if (isset($operations['delete'])) {
      $operations['delete']['title'] = $this->t('Delete vocabulary');
    }

    if ($entity->access('access taxonomy overview')) {
      $operations['list'] = [
        'title' => t('List terms'),
        
protected function getEntityIds() {
    return $this->getStorage()->getQuery()
      ->condition('theme', $this->getThemeName())
      ->sort($this->entityType->getKey('id'))
      ->execute();
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);

    if (isset($operations['edit'])) {
      $operations['edit']['title'] = $this->t('Configure');
    }

    if (isset($operations['delete'])) {
      $operations['delete']['title'] = $this->t('Remove');
    }
    return $operations;
  }

  
'data' => $entity->label(),
      'class' => ['menu-label'],
    ];
    $row['description']['data'] = ['#markup' => $entity->getDescription()];
    return $row + parent::buildRow($entity);
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);

    if (isset($operations['edit'])) {
      $operations['edit']['title'] = t('Edit menu');
      $operations['add'] = [
        'title' => t('Add link'),
        'weight' => 20,
        'url' => $entity->toUrl('add-link-form'),
        'query' => [
          'destination' => $entity->toUrl('edit-form')->toString(),
        ],
      ];
    }
// Only add the pager if a limit is specified.     if ($this->limit) {
      $query->pager($this->limit);
    }
    return $query;
  }

  /** * {@inheritdoc} */
  public function getOperations(EntityInterface $entity) {
    $operations = $this->getDefaultOperations($entity);
    $operations += $this->moduleHandler()->invokeAll('entity_operation', [$entity]);
    $this->moduleHandler->alter('entity_operation', $operations$entity);
    uasort($operations, '\Drupal\Component\Utility\SortArray::sortByWeightElement');

    return $operations;
  }

  /** * Gets this list's default operations. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity the operations are for. * * @return array * The array structure is identical to the return value of * self::getOperations(). */

  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, RedirectDestinationInterface $redirect_destination) {
    parent::__construct($entity_type$storage);

    $this->redirectDestination = $redirect_destination;
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);

    $destination = $this->redirectDestination->get();
    foreach ($operations as $key => $operation) {
      $operations[$key]['query']['destination'] = $destination;
    }

    return $operations;
  }

  /** * {@inheritdoc} */
$header = [
      'type' => t('Action type'),
      'label' => t('Label'),
    ] + parent::buildHeader();
    return $header;
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);
    if (isset($operations['edit'])) {
      $operations['edit']['title'] = t('Configure');
    }
    return $operations;
  }

  /** * {@inheritdoc} */
  public function render() {
    $build['action_admin_manage_form'] = \Drupal::formBuilder()->getForm('Drupal\action\Form\ActionAdminManageForm');
    
if ($active_workspace && $entity->id() === $active_workspace->id()) {
      $row['class'] = ['active-workspace', 'active-workspace--not-default'];
    }
    return $row;
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    /** @var \Drupal\workspaces\WorkspaceInterface $entity */
    $operations = parent::getDefaultOperations($entity);
    if (isset($operations['edit'])) {
      $operations['edit']['query']['destination'] = $entity->toUrl('collection')->toString();
    }

    $active_workspace = $this->workspaceManager->getActiveWorkspace();
    if (!$active_workspace || $entity->id() != $active_workspace->id()) {
      $operations['activate'] = [
        'title' => $this->t('Switch to @workspace', ['@workspace' => $entity->label()]),
        // Use a weight lower than the one of the 'Edit' operation because we         // want the 'Activate' operation to be the primary operation.         'weight' => 0,
        
$row['class'][] = 'menu-disabled';
    }

    return $row;
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    /** @var \Drupal\field\FieldConfigInterface $entity */
    $operations = parent::getDefaultOperations($entity);

    if ($entity->access('update') && $entity->hasLinkTemplate("{$entity->getTargetEntityTypeId()}-field-edit-form")) {
      $operations['edit'] = [
        'title' => $this->t('Edit'),
        'weight' => 10,
        'url' => $entity->toUrl("{$entity->getTargetEntityTypeId()}-field-edit-form"),
        'attributes' => [
          'title' => $this->t('Edit field settings.'),
        ],
      ];
    }
    
'#context' => ['list_style' => 'comma-list'],
      ];
    }

    return $row + parent::buildRow($entity);
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);

    if (isset($operations['edit'])) {
      $operations['edit']['title'] = $this->t('Configure');
    }

    // The fallback format may not be disabled.     if ($entity->isFallbackFormat()) {
      unset($operations['disable']);
    }

    return $operations;
  }
Home | Imprint | This part of the site doesn't use cookies.