You are here

public function Links::render in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/src/Plugin/views/field/Links.php \Drupal\bibcite_entity\Plugin\views\field\Links::render()

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

modules/bibcite_entity/src/Plugin/views/field/Links.php, line 155

Class

Links
Field handler to render links for bibcite entity.

Namespace

Drupal\bibcite_entity\Plugin\views\field

Code

public function render(ResultRow $values) {

  // @todo Find a way to combine view handler code with extra field.
  $build['bibcite_links'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'bibcite-links',
      ],
    ],
    'links' => [
      '#theme' => 'item_list',
      '#attributes' => [
        'class' => [
          'inline',
        ],
      ],
      '#items' => [],
    ],
  ];
  $config = $this->configFactory
    ->get('bibcite_entity.reference.settings');
  if ($this->options['override_default'] && !empty($this->options['links']['overrides'])) {
    $overrides = [
      'links' => $this->options['links']['overrides'],
    ];
    $config
      ->setSettingsOverride($overrides);
  }
  $default_link_attributes = [
    'enabled' => TRUE,
    'weight' => 0,
  ];
  $links_config = $config
    ->get('links');
  foreach ($this->linkPluginManager
    ->getDefinitions() as $plugin_id => $definition) {
    $plugin_config = isset($links_config[$plugin_id]) ? $links_config[$plugin_id] : [];
    $plugin_config = $plugin_config + $default_link_attributes;
    if ($plugin_config['enabled']) {
      $instance = $this->linkPluginManager
        ->createInstance($plugin_id);
      if ($link = $instance
        ->build($this
        ->getEntity($values))) {
        $build['bibcite_links']['links']['#items'][] = $link + [
          '#weight' => $plugin_config['weight'],
        ];
      }
    }
  }
  uasort($build['bibcite_links']['links']['#items'], 'Drupal\\Component\\Utility\\SortArray::sortByWeightProperty');
  return $build;
}