You are here

public function DomainAccessField::getItems in Domain Access 8

Gets an array of items for the field.

Parameters

\Drupal\views\ResultRow $values: The result row object containing the values.

Return value

array An array of items for the field.

Overrides EntityField::getItems

File

domain_access/src/Plugin/views/field/DomainAccessField.php, line 18

Class

DomainAccessField
Field handler to present the link an entity on a domain.

Namespace

Drupal\domain_access\Plugin\views\field

Code

public function getItems(ResultRow $values) {
  $items = parent::getItems($values);

  // Override the default link generator, which wants to send us to the entity
  // page, not the entity we are looking at.
  if (!empty($this->options['settings']['link'])) {
    foreach ($items as &$item) {
      $object = $item['raw'];
      $entity = $object
        ->getEntity();

      // Mark the entity as external to force domain URL prefixing.
      $url = $entity
        ->toUrl('canonical', [
        'external' => TRUE,
      ])
        ->toString();
      $domain = $item['rendered']['#options']['entity'];
      $item['rendered']['#type'] = 'markup';
      $item['rendered']['#markup'] = '<a href="' . $domain
        ->buildUrl($url) . '">' . $domain
        ->label() . '</a>';
    }
    uasort($items, [
      $this,
      'sort',
    ]);
  }
  return $items;
}