Commit 8aab2b28 authored by Andrei Mateescu's avatar Andrei Mateescu
Browse files

Issue #3037357 followup: Missing operations of "Entity subqueue" in created view

parent 52ab2e47
Loading
Loading
Loading
Loading
+6 −41
Changes for src/EntitySubqueueListBuilder.php: 6 added lines, 41 removed lines.
Original line number Diff line number Diff line
@@ -79,56 +79,21 @@ class EntitySubqueueListBuilder extends EntityListBuilder {
   * {@inheritdoc}
   */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);

    $operations['edit']['title'] = $this->t('Edit items');

    /** @var \Drupal\entityqueue\EntityQueueInterface $queue */
    $queue = $entity->getQueue();

    $operations = [];
    // Add the 'edit queue' operation as well.
    if ($queue->access('update') && $queue->hasLinkTemplate('edit-form')) {
      $operations['configure'] = [
        'title' => $this->t('Configure'),
        'title' => $this->t('Configure queue'),
        'weight' => 10,
        'url' => $this->ensureDestination($queue->toUrl('edit-form')),
      ];
    }
    if ($queue->access('delete') && $queue->hasLinkTemplate('delete-form')) {
      $operations['delete'] = [
        'title' => $this->t('Delete'),
        'weight' => 100,
        'url' => $this->ensureDestination($queue->toUrl('delete-form')),
      ];
    }

    if (!$queue->status() && $queue->hasLinkTemplate('enable')) {
      $operations['enable'] = [
        'title' => t('Enable'),
        'weight' => -10,
        'url' => $this->ensureDestination($queue->toUrl('enable')),
      ];
    }
    elseif ($queue->hasLinkTemplate('disable')) {
      $operations['disable'] = [
        'title' => t('Disable'),
        'weight' => 40,
        'url' => $queue->toUrl('disable'),
      ];
    }
    // Add AJAX functionality to enable/disable operations.
    foreach (['enable', 'disable'] as $op) {
      if (isset($operations[$op])) {
        $operations[$op]['url'] = $queue->toUrl($op);
        // Enable and disable operations should use AJAX.
        $operations[$op]['attributes']['class'][] = 'use-ajax';
      }
    }

    // Allow queue handlers to add their own operations.
    $operations += $queue->getHandlerPlugin()->getQueueListBuilderOperations();

    // We provide queue operations on the subqueue list builder, so we need to
    // fire the alter hooks for the queue as well.
    $operations += $this->moduleHandler()->invokeAll('entity_operation', [$queue]);
    $this->moduleHandler->alter('entity_operation', $operations, $queue);
    uasort($operations, '\Drupal\Component\Utility\SortArray::sortByWeightElement');

    return $operations;
  }