views_add_contextual_links example

$class = $route->getOption('_view_display_plugin_class');
    if ($route->getOption('returns_response')) {
      /** @var \Drupal\views\Plugin\views\display\ResponseDisplayPluginInterface $class */
      return $class::buildResponse($view_id$display_id$args);
    }
    else {
      /** @var \Drupal\views\Plugin\views\display\Page $class */
      $build = $class::buildBasicRenderable($view_id$display_id$args$route);
      Page::setPageRenderArray($build);

      views_add_contextual_links($build, 'page', $display_id$build);

      return $build;
    }
  }

  /** * Gets the title of the given view's display. * * @param string $view_id * The id of the view. * @param string $display_id * The id of the display from the view. * * @return string|\Drupal\Component\Render\MarkupInterface * The title of the display of the view. */
if (isset($element['view_build']['#title'])) {
          $element['#title'] = &$element['view_build']['#title'];
        }

        if (empty($view->display_handler->getPluginDefinition()['returns_response'])) {
          // views_add_contextual_links() needs the following information in           // order to be attached to the view.           $element['#view_id'] = $view->storage->id();
          $element['#view_display_show_admin_links'] = $view->getShowAdminLinks();
          $element['#view_display_plugin_id'] = $view->display_handler->getPluginId();
          views_add_contextual_links($element, 'view', $view->current_display);
        }
      }
      if (empty($view->display_handler->getPluginDefinition()['returns_response'])) {
        $element['#attributes']['class'][] = 'views-element-container';
        $element['#theme_wrappers'] = ['container'];
      }
    }

    return $element;
  }

}
      // array, so if the block contains a string of already-rendered markup,       // convert it to an array.       if (is_string($output)) {
        $output = ['#markup' => $output];
      }

      // views_add_contextual_links() needs the following information in       // order to be attached to the view.       $output['#view_id'] = $this->view->storage->id();
      $output['#view_display_show_admin_links'] = $this->view->getShowAdminLinks();
      $output['#view_display_plugin_id'] = $this->view->display_handler->getPluginId();
      views_add_contextual_links($output$block_type$this->displayID);
    }
  }

  /** * Gets the view executable. * * @return \Drupal\views\ViewExecutable * The view executable. * * @todo revisit after https://www.drupal.org/node/3027653. This method was * added in https://www.drupal.org/node/3002608, but should not be * necessary once block plugins can determine if they are being previewed. */
Home | Imprint | This part of the site doesn't use cookies.