You are here

public function AssetInjectorListBuilder::buildRow in Asset Injector 8.2

Same name and namespace in other branches
  1. 8 src/AssetInjectorListBuilder.php \Drupal\asset_injector\AssetInjectorListBuilder::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/AssetInjectorListBuilder.php, line 26

Class

AssetInjectorListBuilder
Provides a listing of Asset Injector entities.

Namespace

Drupal\asset_injector

Code

public function buildRow(EntityInterface $entity) {
  $data['label'] = $entity
    ->label();
  $data['conditions'] = [];

  /** @var \Drupal\Core\Condition\ConditionPluginBase $condition */
  foreach ($entity
    ->getConditionsCollection() as $condition_id => $condition) {
    if ($condition_id == 'current_theme') {
      $config = $condition
        ->getConfiguration();
      $condition
        ->setConfiguration([
        'theme' => implode(', ', $config['theme']),
      ] + $config);
    }
    $data['conditions'][$condition_id] = $this
      ->t('%plugin is configured.', [
      '%plugin' => $condition
        ->getPluginDefinition()['label'],
    ]);

    /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $summary */
    if ($summary = $condition
      ->summary()) {
      $data['conditions'][$condition_id] = Html::decodeEntities($summary
        ->render());
    }
  }
  $data['conditions'] = [
    '#theme' => 'item_list',
    '#list_type' => 'ul',
    '#items' => empty($data['conditions']) ? [
      $this
        ->t('Global'),
    ] : $data['conditions'],
  ];
  $data['conditions'] = render($data['conditions']);
  $row = [
    'class' => $entity
      ->status() ? 'enabled' : 'disabled',
    'data' => $data + parent::buildRow($entity),
  ];
  return $row;
}