You are here

public function GridStackListBuilder::buildRow in GridStack 8

Same name and namespace in other branches
  1. 8.2 modules/gridstack_ui/src/Controller/GridStackListBuilder.php \Drupal\gridstack_ui\Controller\GridStackListBuilder::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 DraggableListBuilder::buildRow

See also

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

File

modules/gridstack_ui/src/Controller/GridStackListBuilder.php, line 80

Class

GridStackListBuilder
Provides a listing of GridStack optionsets.

Namespace

Drupal\gridstack_ui\Controller

Code

public function buildRow(EntityInterface $entity) {
  $icon_uri = $entity
    ->getIconUri();
  $manager = $this->manager;
  $framework = $manager
    ->configLoad('framework', 'gridstack.settings');
  $use_framework = $framework && $entity
    ->getOption('use_framework');
  $row['label'] = Html::escape($entity
    ->label());
  $row['icon'] = [];
  $row['framework'] = [];
  if (!empty($icon_uri)) {
    $row['icon'] = [
      '#theme' => 'blazy',
      '#settings' => [
        'uri' => $icon_uri,
        'lazy' => 'blazy',
      ],
    ];
  }
  $row['framework']['#markup'] = $use_framework ? ucwords($framework) : 'GridStack JS';
  $grids = $entity
    ->getEndBreakpointGrids();
  $nested = $entity
    ->getEndBreakpointGrids('nested');
  $nested = array_filter($nested);
  $counts = [];
  if (!empty($nested)) {
    foreach ($nested as $grid) {
      if (empty($grid)) {
        continue;
      }
      if (is_string($grid)) {
        $grid = Json::decode($grid);
      }
      $boxes = [];
      foreach ($grid as $item) {
        if (!isset($item['width'])) {
          continue;
        }
        $boxes[] = $item['width'];
      }
      $counts = NestedArray::mergeDeep($counts, $boxes);
    }
  }
  $nested_grids = empty($nested) ? '0' : count($counts);
  $row['grids']['#markup'] = $this
    ->t('@grids : @nested', [
    '@grids' => count($grids),
    '@nested' => $nested_grids,
  ]);
  $dependencies = $entity
    ->getDependencies();
  $row['provider']['#markup'] = isset($dependencies['module'][0]) ? $dependencies['module'][0] : 'gridstack';
  return $row + parent::buildRow($entity);
}