You are here

protected function SmartDateFormatListBuilder::makeLinksFromRef in Smart Date 8

Same name and namespace in other branches
  1. 8.2 src/Entity/SmartDateFormatListBuilder.php \Drupal\smart_date\Entity\SmartDateFormatListBuilder::makeLinksFromRef()
  2. 3.x src/Entity/SmartDateFormatListBuilder.php \Drupal\smart_date\Entity\SmartDateFormatListBuilder::makeLinksFromRef()
  3. 3.0.x src/Entity/SmartDateFormatListBuilder.php \Drupal\smart_date\Entity\SmartDateFormatListBuilder::makeLinksFromRef()
  4. 3.1.x src/Entity/SmartDateFormatListBuilder.php \Drupal\smart_date\Entity\SmartDateFormatListBuilder::makeLinksFromRef()
  5. 3.2.x src/Entity/SmartDateFormatListBuilder.php \Drupal\smart_date\Entity\SmartDateFormatListBuilder::makeLinksFromRef()
  6. 3.3.x src/Entity/SmartDateFormatListBuilder.php \Drupal\smart_date\Entity\SmartDateFormatListBuilder::makeLinksFromRef()
  7. 3.4.x src/Entity/SmartDateFormatListBuilder.php \Drupal\smart_date\Entity\SmartDateFormatListBuilder::makeLinksFromRef()

Turn a EntityReferenceFieldItemList into a render array of links.

File

src/Entity/SmartDateFormatListBuilder.php, line 45

Class

SmartDateFormatListBuilder
Defines a class to build a listing of Smart date formats.

Namespace

Drupal\smart_date\Entity

Code

protected function makeLinksFromRef($ref) {

  // No value means nothing to do.
  if (!$ref) {
    return NULL;
  }
  $entities = $ref
    ->referencedEntities();
  $content = [
    '#theme' => 'item_list',
    '#list_type' => 'ul',
    '#wrapper_attributes' => [
      'class' => 'container',
    ],
  ];
  $links = [];
  foreach ($entities as $ref_entity) {
    $links[] = Link::fromTextAndUrl($ref_entity
      ->getTitle(), $ref_entity
      ->toUrl());
  }
  $content['#items'] = $links;
  return $content;
}