You are here

public function BeautytipsManagerController::customTipsOverview in BeautyTips 8

Custom tips administration.

1 string reference to 'BeautytipsManagerController::customTipsOverview'
beautytips_manager.routing.yml in beautytips_manager/beautytips_manager.routing.yml
beautytips_manager/beautytips_manager.routing.yml

File

beautytips_manager/src/Controller/BeautytipsManagerController.php, line 15

Class

BeautytipsManagerController

Namespace

Drupal\beautytips_manager\Controller

Code

public function customTipsOverview() {
  $rows = [];
  $header = [
    $this
      ->t('Element'),
    $this
      ->t('Style'),
    $this
      ->t('Status'),
    $this
      ->t('Visibility'),
    $this
      ->t('Pages'),
    $this
      ->t('operations'),
    '',
  ];
  $tips = beautytips_manager_get_custom_tips();
  if (count($tips)) {
    $visibility = [
      $this
        ->t('Show on every page except the listed pages.'),
      $this
        ->t('Show on only the listed pages.'),
    ];
    foreach ($tips as $tip) {
      $tip->pages = Html::escape($tip->pages);
      $pages = $tip->pages != substr($tip->pages, 0, 40) ? substr($tip->pages, 0, 40) . '...' : substr($tip->pages, 0, 40);
      $rows[$tip->id]['element'] = Html::escape($tip->element);
      $rows[$tip->id]['style'] = $tip->style;
      $rows[$tip->id]['enabled'] = $tip->enabled ? $this
        ->t('Enabled') : $this
        ->t('Disabled');
      $rows[$tip->id]['visibility'] = $visibility[$tip->visibility];
      $rows[$tip->id]['pages'] = $pages;
      $url = Url::fromUserInput("/admin/config/user-interface/beautytips/custom-tips/{$tip->id}/edit");
      $rows[$tip->id]['edit'] = Link::fromTextAndUrl($this
        ->t('edit'), $url)
        ->toString();
      $url = Url::fromUserInput("/admin/config/user-interface/beautytips/custom-tips/{$tip->id}/delete");
      $rows[$tip->id]['delete'] = Link::fromTextAndUrl($this
        ->t('delete'), $url)
        ->toString();
    }
  }
  else {
    return [
      '#type' => 'markup',
      '#markup' => $this
        ->t('There are no custom beautytips yet.'),
    ];
  }
  return [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  ];
}