You are here

function views_ui_view_preview_section_handler_links in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views_ui/views_ui.module \views_ui_view_preview_section_handler_links()
  2. 9 core/modules/views_ui/views_ui.module \views_ui_view_preview_section_handler_links()

Returns contextual links for each handler of a certain section.

@TODO Bring in relationships Refactor this function to use much stuff of views_ui_edit_form_get_bucket.

Parameters

$title: Add a bolded title of this section.

2 calls to views_ui_view_preview_section_handler_links()
template_preprocess_views_ui_view_preview_section in core/modules/views_ui/views_ui.theme.inc
Prepares variables for views UI view preview section templates.
views_ui_view_preview_section_rows_links in core/modules/views_ui/views_ui.module
Returns all contextual links for the main content part of the view.

File

core/modules/views_ui/views_ui.module, line 175
Provide structure for the administrative interface to Views.

Code

function views_ui_view_preview_section_handler_links(ViewExecutable $view, $type, $title = FALSE) {
  $display = $view->display_handler->display;
  $handlers = $view->display_handler
    ->getHandlers($type);
  $links = [];
  $types = ViewExecutable::getHandlerTypes();
  if ($title) {
    $links[$type . '-title'] = [
      'title' => $types[$type]['title'],
    ];
  }
  foreach ($handlers as $id => $handler) {
    $field_name = $handler
      ->adminLabel(TRUE);
    $links[$type . '-edit-' . $id] = [
      'title' => t('Edit @section', [
        '@section' => $field_name,
      ]),
      'url' => Url::fromRoute('views_ui.form_handler', [
        'js' => 'nojs',
        'view' => $view->storage
          ->id(),
        'display_id' => $display['id'],
        'type' => $type,
        'id' => $id,
      ]),
      'attributes' => [
        'class' => [
          'views-ajax-link',
        ],
      ],
    ];
  }
  $links[$type . '-add'] = [
    'title' => t('Add new'),
    'url' => Url::fromRoute('views_ui.form_add_handler', [
      'js' => 'nojs',
      'view' => $view->storage
        ->id(),
      'display_id' => $display['id'],
      'type' => $type,
    ]),
    'attributes' => [
      'class' => [
        'views-ajax-link',
      ],
    ],
  ];
  return $links;
}