You are here

function express_add_content_bean_add in Express 7.2

1 string reference to 'express_add_content_bean_add'
express_add_content_theme_registry_alter in modules/custom/express_add_content/express_add_content.module

File

modules/custom/express_add_content/express_add_content.module, line 87

Code

function express_add_content_bean_add($vars) {

  // Check to see if any content types exist yet
  if ($vars['content']) {
    $output = array();

    // Get bean bundles
    if ($cache = cache_get('express_add_content_express_bean_list_groups')) {
      $bundles = $cache->data;
    }
    else {
      $bundles = module_invoke_all('express_bean_list_groups', $variables = NULL);

      // Save this for 30 days - it should only be cleared on a code update
      cache_set('express_add_content_express_bean_list_groups', $bundles, 'cache', time() + 60 * 60 * 24 * 30);
    }
    uasort($bundles, '_express_add_content_sort_types');

    // Links fromt node_add_list().
    $content = $vars['content'];

    // Build new links list with title as key
    $links = array();

    // $vars['content'] for beans is different than nodes, so build a $links array in the same structure
    foreach ($content as $bean) {
      $key = $bean
        ->getLabel();

      // build bean add path and check access
      $path = 'block/add/' . $bean
        ->buildURL();
      if (drupal_valid_path($path)) {
        $links[$key] = array(
          'title' => $key,
          'href' => $path,
          'description' => $bean
            ->getDescription(),
        );
      }
    }

    // Step through bundles
    foreach ($bundles as $key => $bundle) {
      $output[$key]['title']['#markup'] = '<h2>' . $bundle['title'] . '</h2>';
      $bundle_class = 'bundle-type-' . _express_add_content_string_to_machine($bundle['title']);
      $output[$key]['#prefix'] = '<div class="admin-panel express-add-group ' . $bundle_class . '">';
      $output[$key]['#suffix'] = '</div>';

      // Add content types for each bundle
      $types = '';
      foreach ($bundle['types'] as $type) {
        if (!empty($links[$type])) {
          $types .= '<li class="clearfix">';
          $types .= '<span class="label">' . l($links[$type]['title'], $links[$type]['href']) . '</span>';
          $types .= '<div class="description">' . filter_xss_admin($links[$type]['description']) . '</div>';
          $types .= '</li>';

          // Remove from $links array so we can check for leftovers that are not included in bundles
          unset($links[$type]);
        }
      }

      // Add markup for types, otherwise unset so empty set is not rendered
      if (!empty($types)) {
        $output[$key]['types']['#markup'] = $types;
        $output[$key]['types']['#prefix'] = '<ul class="admin-list">';
        $output[$key]['types']['#suffix'] = '</ul>';
      }
      else {
        unset($output[$key]);
      }
    }

    // Output leftover links that were not assigned to a bundle
    if (!empty($links)) {
      $output['other']['title']['#markup'] = '<h2>Other</h2>';
      $output['other']['#prefix'] = '<div class="admin-panel express-add-group">';
      $output['other']['#suffix'] = '</div>';
      $types = '<ul class="admin-list">';
      foreach ($links as $link) {
        $types .= '<li class="clearfix">';
        $types .= '<span class="label">' . l($link['title'], $link['href']) . '</span>';
        $types .= '<div class="description">' . filter_xss_admin($link['description']) . '</div>';
        $types .= '</li>';
      }
      $types .= '</ul>';
      $output['other']['types']['#markup'] = $types;
    }
    return $output;
  }
  else {
    $output = '<p>' . t('You have not created any content types yet. Go to the <a href="@create-content">content type creation page</a> to add a new content type.', array(
      '@create-content' => url('admin/structure/types/add'),
    )) . '</p>';
    return $output;
  }
}