1 node_type_example.module node_type_example_page()

Callback that builds our content.

Return value

array: A renderable array showing a list of our nodes.

See also

node_load()

node_view()

node_type_example_field_formatter_view()

Related topics

File

modules/examples/node_type_example/node_type_example.module, line 125
Hook implementations for the Node Type Example module.

Code

function node_type_example_page() {
  $renderable_array = array();
  // We query the database and find all the nodes for the type we defined.
  $sql = 'SELECT nid FROM {node} n WHERE n.type = :type AND n.status = :status';
  $result = db_query($sql, array(
    ':type' => 'node_type_example',
    ':status' => 1)
  );
  $renderable_array['explanation'] = array(
    '#markup' => t("The created node_type_example nodes will be displayed here. The color fields will be displayed differently in this list than when you normally view nodes. Click on the node title to see the difference. This is the result of using our 'node_type_example_list' node view type."),
  );
  // Loop through each of our node_type_example nodes and instruct node_view()
  // to use our "node_type_example_list" view.
  // See node_load() and node_view().
  foreach ($result as $row) {
    $node = node_load($row->nid);
    $renderable_array['node_list'][] = node_view($node, 'node_type_example_list');
  }
  return $renderable_array;
}