public function FlagForListListBuilder::buildRow in Flag Lists 8
Same name and namespace in other branches
- 4.0.x src/FlagForListListBuilder.php \Drupal\flag_lists\FlagForListListBuilder::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/
FlagForListListBuilder.php, line 35
Class
- FlagForListListBuilder
- Provides a listing of Flag for list entities.
Namespace
Drupal\flag_listsCode
public function buildRow(EntityInterface $entity) {
$row = [];
$row['label'] = $entity
->label();
$row['id'] = $entity
->id();
$row['owner'] = $entity
->get('owner');
if ($entity
->hasBaseFlag()) {
$flag = \Drupal::service('flag')
->getFlagById($entity
->getBaseFlag());
$flag_url = new Url('');
$row['base_flag'] = Link::fromTextAndUrl($flag
->label(), $flag_url
->fromRoute('entity.flag.edit_form', [
'flag' => $flag
->id(),
]))
->toString();
$bundles = '';
foreach ($flag
->getBundles() as $bundle) {
if (empty($bundles)) {
$bundles = $bundle;
}
else {
$bundles = $bundles . ', ' . $bundle;
}
}
if (empty($bundles)) {
$bundles = '-';
}
$row['entity_type'] = $flag
->getFlaggableEntityTypeId();
$row['bundles'] = $bundles;
$row['scope'] = $flag
->isGlobal() ? $this
->t('Global') : $this
->t('Personal');
}
else {
$row['base_flag'] = $this
->t("<em>Template flag doesn't exist</em>");
$row['entity_type'] = 'unknown';
$row['bundles'] = '-';
$row['scope'] = '-';
}
return $row + parent::buildRow($entity);
}