You are here

public function NodeTypeCountController::nodeTypeCountPublished in Node Type count 8

Constructs a page with descriptive content.

Our router maps this method to the path 'admin/reports/node-type-count'.

1 string reference to 'NodeTypeCountController::nodeTypeCountPublished'
node_type_count.routing.yml in ./node_type_count.routing.yml
node_type_count.routing.yml

File

src/Controller/NodeTypeCountController.php, line 24
Contains \Drupal\node_type_count\Controller\NodeTypeCountController.

Class

NodeTypeCountController
Controller routines for page example routes.

Namespace

Drupal\node_type_count\Controller

Code

public function nodeTypeCountPublished() {

  // We are going to output the results in a table with a nice header.
  $header = array(
    t('Title'),
    t('Type'),
    t('Published'),
    t('UnPublished'),
  );
  $result = node_type_get_names();
  if (is_array($result)) {
    foreach ($result as $node_type_machine_name => $content_type_title) {

      // Get the value as key and value pair.
      $result_arr['title'] = check_plain($content_type_title);
      $result_arr['machine_name'] = $node_type_machine_name;
      $result_arr['published'] = NodeTypeCountController::nodeCountState(NODE_PUBLISHED, $node_type_machine_name);
      $result_arr['unpublished'] = NodeTypeCountController::nodeCountState(NODE_NOT_PUBLISHED, $node_type_machine_name);
      $result_final[$node_type_machine_name] = $result_arr;
    }
  }
  $rows = array();
  foreach ($result_final as $row) {

    // Normally we would add some nice formatting to our rows
    // but for our purpose we are simply going to add our row
    // to the array.
    $rows[] = array(
      'data' => (array) $row,
    );
  }

  // Build the table for the nice output.
  $build = array(
    '#markup' => '<p>' . t('The layout here is a themed as a table
           that is sortable by clicking the header name.') . '</p>',
  );
  $build['tablesort_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  return $build;
}