You are here

protected function JuiceboxFieldFormatter::buildContextualLinks in Juicebox HTML5 Responsive Image Galleries 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldFormatter/JuiceboxFieldFormatter.php \Drupal\juicebox\Plugin\Field\FieldFormatter\JuiceboxFieldFormatter::buildContextualLinks()

Utility to build contextual links for a field-based gallery display.

Parameters

array $xml_route_info: Associative array of route info used to generate the XML.

string $entity_type_id: The entity type for this field instance.

Return value

array An associated array of calculated contextual link information.

1 call to JuiceboxFieldFormatter::buildContextualLinks()
JuiceboxFieldFormatter::viewElements in src/Plugin/Field/FieldFormatter/JuiceboxFieldFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/JuiceboxFieldFormatter.php, line 317

Class

JuiceboxFieldFormatter
Plugin implementation of the 'juicebox' formatter.

Namespace

Drupal\juicebox\Plugin\Field\FieldFormatter

Code

protected function buildContextualLinks(array $xml_route_info, $entity_type_id) {
  $contextual = [];

  // These links won't be reliable unless we have a true field instance.
  if (!$this
    ->isPseudoInstance()) {

    // Add a contextual link to view the XML. Note that we include any query
    // params as route paramaters. These won't be used in the actual route
    // but they will be preserved as query paramaters on the contextual link
    // (which may be needed during the XML request).
    $xml_query = !empty($xml_route_info['options']['query']) ? $xml_route_info['options']['query'] : [];
    $contextual['juicebox_xml_field'] = [
      'route_parameters' => $xml_route_info['route_parameters'] + $xml_query,
    ];

    // Calculate a contextual link that can be used to edit the gallery type.
    // @see \Drupal\juicebox\Plugin\Derivative\JuiceboxConfFieldContextualLinks::getDerivativeDefinitions()
    $bundle = $this->fieldDefinition
      ->getTargetBundle();
    $display_entity = entity_get_display($entity_type_id, $bundle, $this->viewMode);
    $contextual['juicebox_conf_field_' . $entity_type_id] = [
      'route_parameters' => [
        'view_mode_name' => !$display_entity
          ->status() || $display_entity
          ->isNew() ? 'default' : $this->viewMode,
      ],
    ];

    // Some entity types require that a bundle be added to the route params.
    $entity_types = $this->entityTypeManager
      ->getDefinitions();
    $bundle_entity_type = $entity_types[$entity_type_id]
      ->getBundleEntityType();
    if (!empty($bundle_entity_type)) {
      $contextual['juicebox_conf_field_' . $entity_type_id]['route_parameters'][$bundle_entity_type] = $bundle;
    }
  }
  return $contextual;
}