You are here

public function YamlFormOptionsListBuilder::buildRow in YAML Form 8

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/YamlFormOptionsListBuilder.php, line 37

Class

YamlFormOptionsListBuilder
Defines a class to build a listing of form options entities.

Namespace

Drupal\yamlform

Code

public function buildRow(EntityInterface $entity) {

  /** @var \Drupal\yamlform\YamlFormOptionsInterface $entity */
  $row['label'] = $entity
    ->toLink($entity
    ->label(), 'edit-form');
  $row['id'] = $entity
    ->id();
  $options = YamlFormOptions::getElementOptions([
    '#options' => $entity
      ->id(),
  ]);
  $options = OptGroup::flattenOptions($options);
  foreach ($options as $key => &$value) {
    if ($key != $value) {
      $value .= ' (' . $key . ')';
    }
  }
  $row['options'] = implode('; ', array_slice($options, 0, 12)) . (count($options) > 12 ? '; ...' : '');
  $row['alter'] = $entity
    ->hasAlterHooks() ? $this
    ->t('Yes') : $this
    ->t('No');
  return $row + parent::buildRow($entity);
}