You are here

public function AllTableList::content in Views Custom Table 8

Same name and namespace in other branches
  1. 9.0.x src/Controller/AllTableList.php \Drupal\view_custom_table\Controller\AllTableList::content()

Display views custom tables.

Return value

array Return markup array of views custom tables.

1 string reference to 'AllTableList::content'
view_custom_table.routing.yml in ./view_custom_table.routing.yml
view_custom_table.routing.yml

File

src/Controller/AllTableList.php, line 45

Class

AllTableList
Defines AllTableList class.

Namespace

Drupal\view_custom_table\Controller

Code

public function content() {
  if ($this->config) {
    $configData = $this->config
      ->getRawData();
    if (!empty($configData)) {
      $all_database_connections = Database::getAllConnectionInfo();
      foreach ($configData as $rowData) {
        $delete_url = Url::fromRoute('view_custom_table.removecustomtable', [
          'table_name' => $rowData['table_name'],
        ]);
        $edit_url = Url::fromRoute('view_custom_table.editcustomtable', [
          'table_name' => $rowData['table_name'],
        ]);
        $edit_relations_url = Url::fromRoute('view_custom_table.edittablerelations', [
          'table_name' => $rowData['table_name'],
        ]);
        $views_url = Url::fromRoute('view_custom_table.customtable_views', [
          'table_name' => $rowData['table_name'],
        ]);
        $links = [
          [
            '#type' => 'dropbutton',
            '#links' => [
              [
                'title' => $this
                  ->t('Edit'),
                'url' => $edit_url,
              ],
              [
                'title' => $this
                  ->t('Edit Relations'),
                'url' => $edit_relations_url,
              ],
              [
                'title' => $this
                  ->t('Views'),
                'url' => $views_url,
              ],
              [
                'title' => $this
                  ->t('Delete'),
                'url' => $delete_url,
              ],
            ],
          ],
        ];
        $rows[] = [
          'name' => $rowData['table_name'],
          'database' => $all_database_connections[$rowData['table_database']]['default']['database'],
          'description' => $rowData['description'],
          'operations' => render($links),
        ];
      }
      $headers = [
        $this
          ->t('Table Name'),
        $this
          ->t('Database'),
        $this
          ->t('Description'),
        $this
          ->t('Operations'),
      ];
      return [
        '#theme' => 'table',
        '#header' => $headers,
        '#rows' => isset($rows) ? $rows : [],
      ];
    }
    else {
      return [
        '#type' => 'markup',
        '#markup' => $this
          ->t('No entry found for views custom tables'),
      ];
    }
  }
  return [
    '#type' => 'markup',
    '#markup' => $this
      ->t('Module not installed properly, please reinstall module again.'),
  ];
}