You are here

public function PanelizerEntityParagraphsItem::hook_page_alter in Paragraphs 7

Implements hook_page_alter().

File

plugins/panelizer/entity/PanelizerEntityParagraphsItem.class.php, line 124

Class

PanelizerEntityParagraphsItem
Panelizer Entity paragraphs item plugin class.

Code

public function hook_page_alter(&$page) {

  // Add an extra "Panelizer" action on the paragraphs bundles admin page.
  if (current_path() == 'admin/structure/paragraphs') {

    // This only works with some themes.
    if (!empty($page['content']['system_main']['paragraphs_bundle_table'])) {

      // Shortcut.
      $table =& $page['content']['system_main']['paragraphs_bundle_table'];

      // Operations column should always be the last column in header.
      // Increase its colspan by one to include possible panelizer link.
      $operationsCol = end($table['#header']);
      if (!empty($operationsCol['colspan'])) {
        $operationsColKey = key($table['#header']);
        $table['#header'][$operationsColKey]['colspan']++;
      }
      foreach ($table['#rows'] as $bundle => &$row) {
        $bundle_url_str = str_replace('_', '-', $bundle);
        if ($this
          ->is_panelized($bundle) && panelizer_administer_entity_bundle($this, $bundle)) {
          $row[] = array(
            'data' => l(t('panelizer'), 'admin/structure/paragraphs/' . $bundle_url_str . '/panelizer'),
          );
        }
        else {
          $row[] = array(
            'data' => '',
          );
        }
      }
    }
  }
}