You are here

public function GridStackListBuilder::buildRow in GridStack 8.2

Same name and namespace in other branches
  1. 8 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()

1 call to GridStackListBuilder::buildRow()
GridStackVariantListBuilder::buildRow in modules/gridstack_ui/src/Controller/GridStackVariantListBuilder.php
Builds a row for an entity in the entity listing.
1 method overrides GridStackListBuilder::buildRow()
GridStackVariantListBuilder::buildRow in modules/gridstack_ui/src/Controller/GridStackVariantListBuilder.php
Builds a row for an entity in the entity listing.

File

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

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['id'] = [
    '#markup' => $entity
      ->id(),
  ];
  $row['icon'] = [];
  $row['framework'] = [];
  $token_query = [
    IMAGE_DERIVATIVE_TOKEN => time(),
  ];
  $image_url = file_url_transform_relative(file_create_url($icon_uri));
  $image_url .= (strpos($image_url, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($token_query);
  if ($description = $entity
    ->description()) {
    $row['label'] .= '<br><small>' . $description . '</small>';
  }
  if (!empty($icon_uri)) {
    $row['icon'] = [
      '#theme' => 'blazy',
      '#settings' => [
        'uri' => $icon_uri,
        'lazy' => 'blazy',
        'image_url' => $image_url,
      ],
      '#item_attributes' => [
        'width' => 140,
      ],
    ];
  }
  $row['framework']['#markup'] = $use_framework ? ucwords($framework) : 'GridStack/ Native';
  $grids = $entity
    ->getLastBreakpoint();
  $nested = $entity
    ->getLastBreakpoint('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);
}