You are here

public function ThemeSwitcherRuleListBuilder::getOperations in Theme Switcher Rules 8

Provides an array of information to build a list of operation links.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the operations are for.

Return value

array An associative array of operation link data for this list, keyed by operation name, containing the following key-value pairs:

  • title: The localized title of the operation.
  • url: An instance of \Drupal\Core\Url for the operation URL.
  • weight: The weight of this operation.

Overrides EntityListBuilder::getOperations

File

src/Controller/ThemeSwitcherRuleListBuilder.php, line 145

Class

ThemeSwitcherRuleListBuilder
Provides a listing of theme_switcher_rule.

Namespace

Drupal\theme_switcher\Controller

Code

public function getOperations(EntityInterface $entity) {
  $operations = parent::getOperations($entity);

  // Only super-admins may access fast operations.
  if ($this->currentUser
    ->hasPermission('administer theme switcher rules')) {
    if ($entity
      ->status()) {
      $operations['disable'] = [
        'title' => $this
          ->t('Disable'),
        'url' => Url::fromRoute('theme_switcher.inline_action', [
          'op' => 'disable',
          'theme_switcher_rule' => $entity
            ->id(),
        ]),
        'weight' => 50,
      ];
    }
    else {
      $operations['enable'] = [
        'title' => $this
          ->t('Enable'),
        'url' => Url::fromRoute('theme_switcher.inline_action', [
          'op' => 'enable',
          'theme_switcher_rule' => $entity
            ->id(),
        ]),
        'weight' => 40,
      ];
    }
  }
  return $operations;
}