You are here

function farm_settings_toolbar in farmOS 2.x

Implements hook_toolbar().

File

modules/core/settings/farm_settings.module, line 28
Contains farm_settings.module.

Code

function farm_settings_toolbar() {
  $user = \Drupal::currentUser();
  $items = [];
  $items['farm_settings'] = [
    '#cache' => [
      'contexts' => [
        'user.permissions',
      ],
    ],
  ];

  // Add settings to the toolbar if the user has permission.
  if ($user
    ->hasPermission('administer farm settings')) {
    $items['farm_settings'] += [
      '#type' => 'toolbar_item',
      'tab' => [
        '#type' => 'link',
        '#title' => t('Settings'),
        '#url' => Url::fromRoute('farm_settings.settings_page'),
        '#attributes' => [
          'title' => t('Settings'),
          'class' => [
            'toolbar-icon',
            'toolbar-icon-farm-settings',
          ],
        ],
        '#attached' => [
          'library' => [
            'farm_settings/toolbar',
          ],
        ],
      ],
      '#weight' => -5,
    ];
  }
  return $items;
}