Summary

The "Add Section Content" Panel (pictured in attached image) no longer works due to the commit mentioned in comment #5 below.

Steps to recreate

From a fresh install:

  1. Create a new space
  2. Create a new section
  3. 'Customize the page' using the in-place editor
  4. Add the 'Add Section Content' pane to the content (found under the 'Open Atrium' section)
  5. Save the changes and view the page
  6. There is a blank space where the content creation button should be

Error message received

Checking the error log I see the following:
Warning: array_merge(): Argument #1 is not an array in command_buttons_get_button_class() (line 779 of /var/www/html/transtoolkit/docroot/profiles/openatrium/modules/contrib/command_buttons/command_buttons.module).
Notice: Undefined variable: classes in command_buttons_get_button_class() (line 779 of /var/www/html/transtoolkit/docroot/profiles/openatrium/modules/contrib/command_buttons/command_buttons.module).
Warning: Invalid argument supplied for foreach() in command_buttons_entity_view() (line 601 of /var/www/html/transtoolkit/docroot/profiles/openatrium/modules/contrib/command_buttons/command_buttons.module).

Original report

Latest Upgrade affected my custom panel panes module, because it was based on OA's add content panel. Error states the panel is Empty or Inaccessible.

I upgraded to Open Atrium 2.19 and my custom pane is no longer working. When I am editing my panels with IPE the panel (that should have my custom pane) says: Empty or Inaccessible. When I try to add that pane, it still exists as an option, and I get all the fields for settings in that panel, but nothing is rendering. Somehow the content is now considered empty.

Hopefully, this will reveal a necessary edit for others as well in their custom panel panes.

Here is my code:

<?php
/**
 * @file oa_notifications_pane.inc
 */

$plugin = array(
  'title' => t('OAK Add Section Content'),
  'description' => t('Create section content according to allowed content options'),
  'single' => TRUE,
  'category' => array(t('OAK CCT'), -9),
  'edit form' => 'oak_cct_oak_cct_ascp_settings_form',
  'render callback' => 'oak_cct_oak_cct_ascp_render',
  'required context' => new ctools_context_required(t('Node'), 'node'),
  'defaults' => array(
    'description' => '', 
    'image' => '',
    ),
);


/**
 * Provides the form for the widget.
 */
function oak_cct_oak_cct_ascp_settings_form($form, &$form_state) {
  $conf = $form_state['conf'];
  $form['description'] = array(
    '#type' => 'textfield',
    '#title' => t('description text'),
    '#size' => 50,
    '#description' => t('A description.'),
    '#default_value' => !empty($conf['description']) ? $conf['description'] : 'default description',
  );
  $form['image'] = array(
    '#type' => 'textfield',
    '#title' => t('image text'),
    '#size' => 50,
    '#description' => t('An image.'),
    '#default_value' => !empty($conf['image']) ? $conf['image'] : 'default image text',
  );
  // no submit
  return $form;
}


/**
 * Renders the widget.
 */
function oak_cct_oak_cct_ascp_render($subtype, $conf, $args, $context) {
  $block_description = $conf['description'];
  $block_image = $conf['image'];

  $node = $context->data;
  if ($node) {
    $node_types = oa_buttons_get_command_buttons($node);
    if (!empty($node_types)) {

      $buttons = command_buttons_machine_name_load(array_keys($node_types));
      
      // display only if have access to button
      $access = FALSE;
      foreach ($buttons as $key => $button) {
        if (node_access('create', $buttons[$key]->name)) {
          $access = TRUE;
        }


      }

      $item_list = array();
      $classes = array(
        'item_class' => array(
          'btn btn-primary btn-green btn-mini',
          'oa-button',
         ),
        'wrapper_class' => array(
          'oa-buttons',
        ),
      );
      $block = new stdClass();
      if($access){
        $block->title = t('Create Content');
      
	$block->content = "<p>" . $conf['description'] . "</p>" . command_buttons_render_buttons($buttons, $classes, $node_types);
	}
      //$block->description = $conf['description'];
      //$block->image = $conf['image'];
    }
  }
  return $block;
}


/**
 * Submit function, note anything in the formstate[conf] automatically gets saved 
 */
function oak_cct_oak_cct_ascp_settings_form_submit($form, &$form_state) {
  foreach (array_keys($form_state['values']) as $key) {
    if (isset($form_state['values'][$key])) {
      $form_state['conf'][$key] = $form_state['values'][$key];
    }
  }
}

Here are results for various printed variables:

$node_types = 
Array
(
    [oa_wiki_page:11] => Array
        (
            [value] => oa_wiki_page
            [provider_type] => oa_section
            [id] => 11
        )

)
$buttons = 
Array
(
)

It seems to me that the issue could be here:

$buttons = command_buttons_machine_name_load(array_keys($node_types));

For some reason, this function is now giving an empty $buttons array, where before the update, it was not empty.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

SweetTomato’s picture

Issue summary: View changes
SweetTomato’s picture

Some research that may help:

The last commit: https://github.com/phase2/openatrium-drops-7/commit/8529d9201be88fc59378...
Looks like this changed:

For the function: command_buttons_machine_name_load

$results = db_select('command_buttons', 'b')
->fields('b', array('bid'))
- ->condition('bundle', 'node_add')
->condition('name', $buttons, 'IN')
+ ->orderBy('title')
->execute();

Or it is possible that the array_keys function is not working as it used to... and therefore isn't feeding the correct thing to the command_buttons_machine_name_load function.

SweetTomato’s picture

Don't know why, especially since that piece of the code hasn't changed in this update, but removing ->condition('name', $buttons, 'IN') from #2 above seems to fix my issue...

SweetTomato’s picture

I also for some reason thought maybe the keys from the node_array might be a problem (they look like this: oa_wiki_article:11).

So changing the command_buttons_machine_name_load function to the following worked. I basically go through the $buttons array (the one in the function, not the empty one from my tests above) and take out the colon and trailing number:

  foreach($buttons as $key => $value) {
    $arr = explode(":", $value, 2);
    $first = $arr[0];
    $buttons[$key] = $first;
  }
  $results = db_select('command_buttons', 'b')
    ->fields('b', array('bid'))
    ->condition('name', $buttons, 'IN')
    ->orderBy('title')
    ->execute();

Again, not sure why this works, or what the reason or implication is for the change. As well as why or where that colon and trailing number were added to that array in the latest release of OA2.

SweetTomato’s picture

Hmm... looks like the change in the array_key mentioned above is from the latest commit:

In this function _oa_buttons_get_node_command_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,
SweetTomato’s picture

Title: Latest Upgrade affected custom panel panes module. Empty or Inaccessible. » Upgrade 2.19 Breaks Native OA "Add Section Content" Panel
Category: Support request » Bug report
Issue summary: View changes
SweetTomato’s picture

JKingsnorth’s picture

JKingsnorth’s picture

Issue summary: View changes

Marked #2281845: Command List Panes not working as a duplicate, added error message described there to the issue summary here.

JKingsnorth’s picture

Title: Upgrade 2.19 Breaks Native OA "Add Section Content" Panel » "Add Section Content" panel is empty
Version: 7.x-2.19 » 7.x-2.32

This still appears to be an issue in 2.3.2

To recreate the error on a fresh installation:

  • Customise a section page
  • Add the 'Add Section Content' pane (under OA Admin tab)
  • Save, view page, no 'Create [node type]' button is displayed.
JKingsnorth’s picture

Version: 7.x-2.32 » 7.x-2.33

Still reproducible in 2.3.3

hefox’s picture

Status: Active » Fixed

hm, switched it to use 'value' property returned to that function, but guessing it needs further improvement later but that's what the similar spaces one does.

JKingsnorth’s picture

Hi hefox, can you point to the commit for this so we can apply the patch?

hefox’s picture

0348d9635eb20f099b93947aab9c79af13fd04c2 in oa_core

JKingsnorth’s picture

Great, and confirmed working for us too. Thanks hefox.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.