You are here

public function SimpleMegaMenuListBuilder::buildRow in Simple Mega Menu 2.0.x

Same name and namespace in other branches
  1. 8 src/SimpleMegaMenuListBuilder.php \Drupal\simple_megamenu\SimpleMegaMenuListBuilder::buildRow()

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

src/SimpleMegaMenuListBuilder.php, line 81

Class

SimpleMegaMenuListBuilder
Defines a class to build a listing of Simple mega menu entities.

Namespace

Drupal\simple_megamenu

Code

public function buildRow(EntityInterface $entity) {

  /* @var $entity \Drupal\simple_megamenu\Entity\SimpleMegaMenu */
  $row['id'] = $entity
    ->id();
  $row['name'] = Link::fromTextAndUrl($entity
    ->label(), new Url('entity.simple_mega_menu.edit_form', [
    'simple_mega_menu' => $entity
      ->id(),
  ]));
  $bundle = $entity
    ->bundle();

  /* @var \Drupal\simple_megamenu\Entity\SimpleMegaMenuTypeInterface  $simple_mega_menu_type */
  $simple_mega_menu_type = $this->entityTypeManager
    ->getStorage('simple_mega_menu_type')
    ->load($bundle);
  $row['type'] = $simple_mega_menu_type
    ->label();
  $target_menus = $simple_mega_menu_type
    ->getTargetMenu();
  $target_menus = array_filter($target_menus);
  $menu_labels = [];
  foreach ($target_menus as $menu_name) {
    $menu_labels[] = $this->entityTypeManager
      ->getStorage('menu')
      ->load($menu_name)
      ->label();
  }
  $labels = implode(', ', $menu_labels);
  $row['target_menu'] = new FormattableMarkup('@labels', [
    '@labels' => $labels,
  ]);
  return $row + parent::buildRow($entity);
}