You are here

public function FieldController::fieldList in Display Suite 8.2

Same name and namespace in other branches
  1. 8.4 src/Controller/FieldController.php \Drupal\ds\Controller\FieldController::fieldList()
  2. 8.3 src/Controller/FieldController.php \Drupal\ds\Controller\FieldController::fieldList()

Builds a list of fields.

1 string reference to 'FieldController::fieldList'
ds.routing.yml in ./ds.routing.yml
ds.routing.yml

File

src/Controller/FieldController.php, line 56

Class

FieldController
Route controller fields.

Namespace

Drupal\ds\Controller

Code

public function fieldList() {
  $custom_fields = $this->storage
    ->listAll('ds.field.');
  if (!empty($custom_fields)) {
    $rows = array();
    foreach ($custom_fields as $config) {
      $field_value = $this
        ->config($config)
        ->get();
      $row = array();
      $row[] = array(
        'data' => array(
          '#plain_text' => $field_value['label'],
        ),
      );
      $row[] = isset($field_value['type_label']) ? $field_value['type_label'] : $this
        ->t('Unknown');
      $row[] = $field_value['id'];
      $row[] = ucwords(str_replace('_', ' ', implode(', ', $field_value['entities'])));
      $operations = array();
      $operations['edit'] = array(
        'title' => $this
          ->t('Edit'),
        'url' => new Url('ds.manage_field', array(
          'field_key' => $field_value['id'],
        )),
      );
      $operations['delete'] = array(
        'title' => $this
          ->t('Delete'),
        'url' => new Url('ds.delete_field', array(
          'field_key' => $field_value['id'],
        )),
      );
      $this->moduleHandler
        ->alter('ds_field_operations', $operations, $field_value);
      $row[] = array(
        'data' => array(
          '#type' => 'operations',
          '#subtype' => 'ds',
          '#links' => $operations,
        ),
      );
      $rows[] = $row;
    }
    $build = array(
      '#theme' => 'table',
      '#header' => array(
        'Label',
        'Type',
        'Machine name',
        'Entities',
        'Operations',
      ),
      '#rows' => $rows,
    );
  }
  else {
    $build = array(
      '#markup' => $this
        ->t('No custom fields have been defined.'),
    );
  }
  return $build;
}