0

How would I change the category from "Fielded panes" in Panels IPE to something else?

I can accomplish this through the following code:

function template_preprocess_panels_add_content_modal(&$vars) {
  $i = 0;
  foreach($vars['categories_array'] as $item) {
    $new_item = str_replace("Fielded panes", "New Content", $item);
    $vars['categories_array'][$i] = $new_item;
    $i++;
  }
}

However, I'd like to find a more elegant solution by altering the category name in a function that runs before template_preprocess_panels_add_content_modal().

0

Have a look at template_preprocess_panels_add_content_modal() and $vars['categories']. You should be able to override the category names there.

Edit:

Ahh, yes, I forgot about hook_ctools_content_subtype_alter(). That's more elegant :)

From the documentation:

This hook can be used to add things like 'render last' or change icons or categories or to rename content on specific sites.

In the example below the category "Fielded panes" is changed to "New category name".

/**
 * Implements hook_ctools_content_subtype_alter().
 */
function MYMODULE_ctools_content_subtype_alter(&$subtype, &$plugin) {
  if ($subtype['category'] == 'Fielded panes') {
    $subtype['category'] = 'New category name';
  }
}
  • By the time that function runs, $vars['categories_array'] has already been built, and so overriding $vars['categories'] doesn't do anything. – carsonw Jul 29 '14 at 15:26
0

After some research, I discovered that this can easily be accomplished via hook_ctools_content_subtype_alter().

  /**
  * Implements hook_ctools_content_subtype_alter().
  */
  function MYMODULE_ctools_content_subtype_alter(&$subtype, &$plugin) {
    if ($subtype['category'] == 'Fielded panes') {
      $subtype['category'] = 'New category name';
    }
  }

I also discovered that I can alter the title and the icon by doing something like this:

/**
* Implements hook_ctools_content_subtype_alter().
*/
function MYMODULE_ctools_content_subtype_alter(&$subtype, &$plugin) {
  // Change title and icon for rich_text Fielded panel pane content
  if (isset($subtype['bundle']) && $subtype['bundle'] == 'rich_text') {
    $subtype['title'] = 'Custom Content';
    $subtype['path'] = 'sites/default/files/ctools/icons';
    $subtype['icon'] = 'content.png';
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.