Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions modules/oa_buttons/oa_buttons.module
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,17 @@ function oa_buttons_get_node_type_options() {
* Determines which command buttons should be shown within the current context.
*/
function oa_buttons_get_command_buttons($node) {
$node_types = node_type_get_names();
$buttons = array();
$node_types = array_flip(node_type_get_names());
_oa_buttons_get_space_command_buttons($node, $buttons);
_oa_buttons_get_parent_command_buttons($node, $buttons);
// look for node_add command buttons and check the 'create X content'
// node_access dynamically so we don't show command buttons the user
// cannot acccess
foreach ($buttons as $key => $button) {
if (in_array($key, $node_types) && !node_access('create', $key)) {
unset($buttons[$key]);
foreach ($buttons as $button) {
$entity_type = $button['value'];
if (in_array($entity_type, $node_types) && !node_access('create', $entity_type)) {
unset($buttons[$entity_type]);
}
}
drupal_alter('oa_buttons_add_content', $buttons, $node);
Expand Down Expand Up @@ -158,8 +159,11 @@ function _oa_buttons_get_node_command_buttons($node, &$buttons) {

if (!empty($node_options)) {
foreach ($node_options as $opt) {
if (!isset($buttons[$opt['value']])) {
$buttons[$opt['value']] = array(
// There may be more than one node created using the same content type. If
// we want to add each possibility to the command button list we need to
// add the nid to the array key so they are unique.
if (!isset($buttons[$opt['value'] . ':' . $node->nid])) {
$buttons[$opt['value'] . ':' . $node->nid] = array(
'value' => $opt['value'],
'provider_type' => $node->type,
'id' => $node->nid,
Expand Down
23 changes: 17 additions & 6 deletions modules/oa_buttons/plugins/content_types/add_space_content.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,36 @@ function oa_buttons_add_space_content_render($subtype, $conf, $args, $context) {
$content = $cache->data;
}
else {
$node_types = oa_buttons_get_command_buttons($node);
if (count($node_types)) {
drupal_alter('oa_space_buttons', $node_types);
$buttons = command_buttons_machine_name_load(array_keys($node_types));
$buttons = oa_buttons_get_command_buttons($node);
if (count($buttons)) {
drupal_alter('oa_space_buttons', $buttons);
$command_buttons = array();
$node_types = array_flip(node_type_get_names());
// Iterate over each of the buttons.
foreach ($buttons as $button) {
$entity_type = $button['value'];
if (in_array($entity_type, $node_types)) {
if (!isset($command_buttons[$entity_type])) {
$command_buttons[$entity_type] = $entity_type;
}
}
}
$entities = command_buttons_machine_name_load(array_keys($command_buttons));
$item_list = array();
$classes = array(
'use_dropdowns' => TRUE,
'dropdown_label' => t('Create Content'),
'item_class' => array(
'oa-button',
),
),
'wrapper_class' => array(
'oa-buttons',
'btn',
'btn-inverse',
),
);

$content = command_buttons_render_buttons($buttons, $classes, $node_types);
$content = command_buttons_render_buttons($entities, $classes, $buttons);

// Cache for 1 hour.
cache_set($cache_key, $content, 'cache_oa_section_buttons', time() + 6000);
Expand Down