You are here

public function SiteSettingEntityListBuilder::buildOperations in Site Settings and Labels 8

Builds a renderable list of operation links for the entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity on which the linked operations will be performed.

Return value

array A renderable array of operation links.

Overrides EntityListBuilder::buildOperations

See also

\Drupal\Core\Entity\EntityListBuilder::buildRow()

File

src/SiteSettingEntityListBuilder.php, line 330

Class

SiteSettingEntityListBuilder
Defines a class to build a listing of Site Setting entities.

Namespace

Drupal\site_settings

Code

public function buildOperations(EntityInterface $entity) {
  $build = [
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
  ];
  $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');
  $build['operations'] = [
    '#prefix' => '<div class="align-left clearfix">',
    '#type' => 'operations',
    '#links' => $operations,
    '#suffix' => '</div>',
  ];

  // Add new operation.
  $entity_bundle = $entity
    ->bundle();
  if (isset($this->bundles[$entity_bundle]) && $this->bundles[$entity_bundle]->multiple) {
    $url = new Url('entity.site_setting_entity.add_form', [
      'site_setting_entity_type' => $entity_bundle,
    ]);
    if ($url
      ->access()) {
      $build['add'] = [
        '#prefix' => '<div class="align-right">',
        '#type' => 'link',
        '#title' => $this
          ->t('Add another'),
        '#url' => $url,
        '#attributes' => [
          'class' => [
            'button',
          ],
        ],
        '#suffix' => '</div>',
      ];
    }
  }
  return $build;
}