You are here

public function PanelizerEntityNode::hook_page_alter in Panelizer 7.3

Same name and namespace in other branches
  1. 7.2 plugins/entity/PanelizerEntityNode.class.php \PanelizerEntityNode::hook_page_alter()

File

plugins/entity/PanelizerEntityNode.class.php, line 197
Class for the Panelizer node entity plugin.

Class

PanelizerEntityNode
Panelizer Entity node plugin class.

Code

public function hook_page_alter(&$page) {

  // Add an extra "Panelizer" action on the content types admin page.
  if ($_GET['q'] == 'admin/structure/types') {

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

      // Shortcut.
      $table =& $page['content']['system_main']['node_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']++;
      }

      // Since we can't tell what row a type is for, but we know that they
      // were generated in this order, go through the original types list.
      $types = node_type_get_types();
      $names = node_type_get_names();
      $row_index = 0;
      foreach ($names as $bundle => $name) {
        $type = $types[$bundle];
        if (node_hook($type->type, 'form')) {
          $type_url_str = str_replace('_', '-', $type->type);
          if ($this
            ->is_panelized($bundle) && panelizer_administer_entity_bundle($this, $bundle)) {
            $table['#rows'][$row_index][] = array(
              'data' => l(t('panelizer'), 'admin/structure/types/manage/' . $type_url_str . '/panelizer'),
            );
          }
          else {
            $table['#rows'][$row_index][] = array(
              'data' => '',
            );
          }

          // Update row index for next pass.
          $row_index++;
        }
      }
    }
  }
}