1 block.create.inc DashboardCreateBlock::getContent()

Return the content of a block.

Return value

mixed:

Overrides Block::getContent

File

core/modules/dashboard/includes/block.create.inc, line 51
Dashboard block providing links to create new content.

Class

DashboardCreateBlock
@file Dashboard block providing links to create new content.

Code

function getContent() {
  $node_types = node_type_get_types();
  $no_access = TRUE;
  $create = array();

  foreach ($node_types as $machine => $node_type) {
    // If enabled or all types are enabled.
    if (in_array($machine, $this->settings['types']) || empty($this->settings['types'])) {
      // Check access, then add a link to create content.
      if (node_access('create', $machine)) {
        $type_url_str = str_replace('_', '-', $node_type->type);
        $create[] = l(t('Add new @type', array('@type' => t($node_type->name))), 'node/add/' . $type_url_str, array('html' => TRUE));
        $no_access = FALSE;
      }
    }
  }

  // If there are existing content types, but user has no access to create any
  // of them, hide the block completely.
  if ($no_access) {
    return array();
  }

  $build = array(
    '#theme' => 'dashboard_panel__create',
  );
  if (empty($create)) {
    $build['list'] = array(
      '#type' => 'markup',
      '#markup' => t('No content types have been configured yet.'),
    );
  }
  else {
    $build['list'] = array(
      '#theme' => 'item_list',
      '#items' => $create,
    );
  }

  return $build;
}