/** * Render a list of entries in the database. */ public function listOfGroupings() { $content = array(); $content['add_group'] = $this->formBuilder()->getForm('Drupal\\ea_groupings\\EAGroupingsAddForm'); $content['message'] = array('#markup' => $this->t('Generate a list of all groupings on the site.')); $row = array(); $rows = array(); $header = array(array('data' => $this->t('ID'), 'field' => 'groupings.gid'), NULL, array('data' => $this->t('Title'), 'field' => 'groupings.title'), array('data' => $this->t('Parent')), $this->t('View'), $this->t('Edit'), $this->t('Delete')); foreach ($groupings = EAGroupingsStorage::loadSorted($header) as $grouping) { $row = array(); $row['data']['gid'] = $grouping->gid; $row['data']['logo'] = NULL; if (!empty($grouping->logo_fid)) { $file = File::load($grouping->logo_fid); if ($file) { $logo_url = ImageStyle::load('ea_groupings_50x50')->buildUrl($file->getFileUri()); $image_array = array('#theme' => 'image', '#uri' => $logo_url, '#alt' => $this->t('Logo for @grouping', array('@grouping' => $grouping->title)), '#title' => $this->t('@grouping', array('@grouping' => $grouping->title))); $rendered_image = \Drupal::service('renderer')->render($image_array); $row['data']['logo'] = $rendered_image; } } $row['data']['title'] = $grouping->title; $row['data']['parent_title'] = NULL; // Load parent grouping to get title. if (!empty($grouping->parent_gid)) { $parent_grouping_entries = EAGroupingsStorage::load(array('gid' => $grouping->parent_gid)); if ($parent_grouping_entries) { $parent_grouping = $parent_grouping_entries[0]; $row['data']['parent_title'] = $parent_grouping->title; } } // Format view link. $view_link_url = Url::fromRoute('ea_groupings.grouping', array('grouping' => $grouping->gid)); $view_link = \Drupal::l($this->t('View'), $view_link_url); // Format edit link. $edit_link_url = Url::fromRoute('ea_groupings.edit', array('grouping' => $grouping->gid)); $edit_link = \Drupal::l($this->t('Edit'), $edit_link_url); // Format delete link. $delete_link_url = Url::fromRoute('ea_groupings.delete', array('grouping' => $grouping->gid)); $delete_link = \Drupal::l($this->t('Delete'), $delete_link_url); // Add links to row. $row['data']['view_link'] = $view_link; $row['data']['edit_link'] = $edit_link; $row['data']['delete_link'] = $delete_link; // Remove all unused variables. $rows[] = $row; } $content['table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => t('No groupings available.')); $altered_table = \Drupal::moduleHandler()->invokeAll('ea_groupings_alter_table', array($content['table'])); if (!empty($altered_table)) { $content['table'] = $altered_table; } $content['pager'] = array('#type' => 'pager'); return $content; }