There are a lot of different use cases with the IPE (i.e #1570120: Add a button for adding CSS id or CSS class for a region in IPE) and it would be nice to have a way to inject new things into the IPE toolbar without requiring them to all be added to the core. I think that a basic style + configuration option is sufficent for most users with the IPE, but can see advanced users wanting everything from CSS IDs to visibility rules to caching plugins.

The specific need would be to have an alter hook run in $links in theme_panels_ipe_pane_wrapper() which will allow new things to be added and to have old things changed if that is needed. I know this is already a theme function, but I think there is value on more of a data level to change the actual links. This could also help improve that function by having Panels IPE implement the hook to add its default links so the theme function is actually much cleaner.

Comments

merlinofchaos’s picture

StatusFileSize
new405 bytes

To start with, the basic thing we need here is really simple. That very simple patch is attached.

It is made more complicated when I go to try to make it possible for regions, because regions aren't using theme('links') like panes, they're just appending links together. Doh. So that code will need to be adjusted to use theme('links').

At that point, I start looking at this and thinking that we should be using a preprocess for a bunch of this, because having a drupal_alter inside a theme function seems quite wrong.

merlinofchaos’s picture

Status: Active » Needs review
StatusFileSize
new6.08 KB

This more complex patch does everything I suggested in #1.

It required some CSS changes and the elimination of some unnecessary javascript that was moving buttons around.

beeradb’s picture

The current patch is functional, but throws a PHP notice if your hook implementation defines the $renderer variable.

From the drupal_alter() documentation: "A maximum of 2 alterable arguments is supported. In case more arguments need to be passed and alterable, modules provide additional variables assigned by reference in the last $context argument:".

With that in mind, it looks like the two drupal_alter calls should be moved from this:

drupal_alter('panels_ipe_pane_links', $vars['links'], $pane, $display, $renderer);
drupal_alter('panels_ipe_region_links', $vars['links'], $region_id, $display, $renderer);

to:

drupal_alter('panels_ipe_pane_links', $vars['links'], array($pane, $display, $renderer));
drupal_alter('panels_ipe_region_links', $vars['links'], array($region_id, $display, $renderer));

Here's the drupal_alter implementation I used which worked (without throwing notices), for anyone following behind.

function mymodule_panels_ipe_pane_links_alter(&$links, $pane, $display) {

  $links['global'] = array(
    'title' => t('my global custom link'),
    'href' => '<front>',
  );

  if ($pane->panel == 'contentmain') {
      $links['custom_admin'] = array(
        'title' => t('Custom admin link'),
        'href' => 'admin',
        'attributes' => array(
          'class' => 'mycustomclass',
        ),
    ); 
  }
}
beeradb’s picture

StatusFileSize
new6.27 KB

Here's a patch with the proposed changes.

Mostly.. at least. The drupal_alter calls now look like this:

 $context = array(
    'pane' => &$pane,
    'display' => &$display,
    'renderer' => &$renderer
  );
  drupal_alter('panels_ipe_pane_links', $vars['links'], $context);
beeradb’s picture

StatusFileSize
new6.26 KB

And here's a version without explicitly passing the context objects by reference, as per conversations with Earl in IRC.

merlinofchaos’s picture

Status: Needs review » Fixed

Great! Committed and pushed!

Status: Fixed » Closed (fixed)

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

globexplorer’s picture

Here I wanted to add a access settings button. $renderer->get_url('access-settings') is the entry point.
Example:

function panopoly_pages_panels_ipe_pane_links_alter(&$links, $context) {

	$renderer = $context['renderer'];
	$pane = $context['pane'];

  // Add option to add items in the IPE
  $links['access_settings'] = array(
    'title' => t('Access Settings'),
    'href' => $renderer->get_url('access-settings','pane',$pane->pid),
    'html' => FALSE,
    'attributes' => array(
    	'class' => array('ctools-use-modal', 'panels-ipe-hide-bar'),
      'title' => t('Configure'),
  	   ),
  	);

}

But an error occurs. WHY?


An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /panels/ajax/ipe/access-settings/panel_context%3Apage-produkte_br_mitgliedschaft%3A%3Apage_produkte_br_mitgliedschaft_panel_context%3A%3A%3A%3A/pane/22
StatusText: OK

globexplorer’s picture

And now no error occurs!

See the difference. When you edit something you have to take this as an entry point.


  $content_type = ctools_get_content_type($pane->type);
  $subtype = ctools_content_get_subtype($content_type, $pane->subtype);

  if (ctools_content_editable($content_type, $subtype, $pane->configuration)) {
    $links['access_add_test'] = array(
      'title' => isset($content_type['edit text']) ? '<span>' . $content_type['edit text'] . '</span>' : '<span>' . t('Settings') . '</span>',
      'href' => $renderer->get_url('access_add_test', $pane->pid),
      'html' => TRUE,
      'attributes' => array(
        'class' => array('ctools-use-modal', 'panels-ipe-hide-bar'),
        'title' => isset($content_type['edit text']) ? $content_type['edit text'] : t('Settings'),
        // 'id' => "pane-edit-panel-pane-$pane->pid",
      ),
    );
  }


merlinofchaos’s picture

Your use of get_url() doesn't seem to match what Panels is using for the same URL.

      $visibility_links[] = array(
        'title' => t('Settings'),
        'href' => $this->get_url('access-settings', $pane->pid),
        'attributes' => array('class' => array('ctools-use-modal')),
      );

That's just the general settings page, which isn't going to give you much. The way the regular UI is using access means that you'll probably need to do more extensive UI work to make it actually work with IPE.

merlinofchaos’s picture

Whoops. I posted #10 before I saw #9. Looks like you sorted it, so ignore me. :)

globexplorer’s picture

No problem. I already applied two pane buttons to add and configure visibility rules. Working with this module is fun. Thanks!

  • Commit 4e636d7 on 7.x-3.x, 7.x-3.x-i18n, 8.x-3.x by merlinofchaos:
    Issue #1772846 by merlinofchaos, beeradb | populist: Added Create a Hook...