You are here

public function OwnTableList::content in Views Custom Table 8

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

Display views custom table for the current user.

Return value

array Return markup array of views custom table created by current user.

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

File

src/Controller/OwnTableList.php, line 55

Class

OwnTableList
Defines OwnTableList 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) {
        if ($this->account
          ->id() == $rowData['created_by']) {
          $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.'),
  ];
}