You are here

class PanelizerEntityNode in Panelizer 7.3

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

Panelizer Entity node plugin class.

Handles node specific functionality for Panelizer.

Hierarchy

Expanded class hierarchy of PanelizerEntityNode

1 string reference to 'PanelizerEntityNode'
node.inc in plugins/entity/node.inc

File

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

View source
class PanelizerEntityNode extends PanelizerEntityDefault {
  public $entity_admin_root = 'admin/structure/types/manage/%panelizer_node_type';
  public $entity_admin_bundle = 4;
  public $views_table = 'node';
  public $uses_page_manager = TRUE;
  public $supports_revisions = TRUE;
  public function entity_access($op, $entity) {

    // This must be implemented by the extending clas.
    return node_access($op, $entity);
  }

  /**
   * Implement the save function for the entity.
   */
  public function entity_save($entity) {
    if (module_exists('workbench_moderation') && workbench_moderation_node_type_moderated($entity->type)) {
      $live_entity = workbench_moderation_node_live_load($entity);
      if ($live_entity->vid != $entity->vid) {
        $entity->revision = TRUE;
      }
    }
    node_save($entity);

    // Clear page cache. This replaces the need for cache_clear_all() which is
    // normally called by node_form_submit().
    $internal_path = entity_uri('node', $entity);
    $url = url($internal_path['path'], array(
      'absolute' => TRUE,
    ));
    cache_clear_all($url, 'cache_page');
  }
  public function entity_identifier($entity) {
    return t('This node');
  }
  public function entity_bundle_label() {
    return t('Node type');
  }

  /**
   * Determine if the entity allows revisions.
   */
  public function entity_allows_revisions($entity) {
    $retval = array();
    list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
    $node_options = variable_get('node_options_' . $bundle, array(
      'status',
      'promote',
      'panelizer',
    ));

    // Whether or not the entity supports revisions. Drupal core supports
    // revisions by default on nodes; if Workbench Moderation is enabled it's
    // possible to disable this.
    $retval[0] = TRUE;
    if (module_exists('workbench_moderation')) {
      $retval[0] = in_array('panelizer', $node_options);
    }

    // Whether or not the user can control if a revision is created.
    $retval[1] = user_access('administer nodes');

    // Whether or not the revision is created by default.
    $retval[2] = in_array('revision', $node_options);
    return $retval;
  }

  /**
   * {@inheritdoc}
   */
  function get_default_display($bundle, $view_mode) {
    $display = parent::get_default_display($bundle, $view_mode);

    // Add the node title to the display since we can't get that automatically.
    $display->title = '%node:title';

    // Add the node links, they probably would like these.
    $pane = panels_new_pane('node_links', 'node_links', TRUE);
    $pane->css['css_class'] = 'link-wrapper';
    $pane->configuration['build_mode'] = $view_mode;
    $pane->configuration['context'] = 'panelizer';

    // @todo -- submitted by does not exist as a pane! That's v. sad.
    $display
      ->add_pane($pane, 'center');
    unset($pane);

    // If the content type is enabled for use with Webform, add the custom
    // submission pane.
    if (module_exists('webform')) {
      if ($view_mode == 'page_manager') {
        if (variable_get('webform_node_' . $bundle)) {
          $pane = panels_new_pane('entity_field_extra', 'node:webform', TRUE);
          $pane->configuration['context'] = 'panelizer';
          $pane->configuration['view_mode'] = 'full';
          $display
            ->add_pane($pane, 'center');
          unset($pane);
        }
      }
    }

    // Add a custom pane for the book navigation block for the Page Manager
    // display.
    if (module_exists('book')) {
      if ($view_mode == 'page_manager') {
        $pane = panels_new_pane('node_book_nav', 'node_book_nav', TRUE);
        $pane->configuration['context'] = 'panelizer';
        $display
          ->add_pane($pane, 'center');
        unset($pane);
      }
    }
    return $display;
  }

  /**
   * Implements a delegated hook_page_manager_handlers().
   *
   * This makes sure that all panelized entities have the proper entry
   * in page manager for rendering.
   */
  public function hook_default_page_manager_handlers(&$handlers) {
    $handler = new stdClass();
    $handler->disabled = FALSE;

    /* Edit this to true to make a default handler disabled initially */
    $handler->api_version = 1;
    $handler->name = 'node_view_panelizer';
    $handler->task = 'node_view';
    $handler->subtask = '';
    $handler->handler = 'panelizer_node';
    $handler->weight = -100;
    $handler->conf = array(
      'title' => t('Node panelizer'),
      'context' => 'argument_entity_id:node_1',
      'access' => array(),
    );
    $handlers['node_view_panelizer'] = $handler;
    return $handlers;
  }

  /**
   * Implements a delegated hook_form_alter.
   *
   * We want to add Panelizer settings for the bundle to the node type form.
   */
  public function hook_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == 'node_type_form') {
      if (isset($form['#node_type'])) {
        $bundle = $form['#node_type']->type;
        $this
          ->add_bundle_setting_form($form, $form_state, $bundle, array(
          'type',
        ));
      }

      // Additional workflow options when Workbench Moderation is enabled.
      if (module_exists('workbench_moderation')) {

        // It's now possible to disable revision creation through the Panelizer
        // interface.
        $form['workflow']['node_options']['#options']['panelizer'] = t('Enable Panelizer revisions');

        // Disable the 'revision' checkbox when the 'moderation' checkbox is
        // checked, so that moderation can not be enabled unless revisions are
        // enabled.
        $form['workflow']['node_options']['revision']['#states'] = array(
          'disabled' => array(
            ':input[name="node_options[panelizer]"]' => array(
              'checked' => FALSE,
            ),
          ),
        );

        // Disable the 'moderation' checkbox when the 'revision' checkbox is
        // not checked, so that revisions can not be turned off without also
        // turning off moderation.
        $form['workflow']['node_options']['panelizer']['#description'] = t('Revisions must be enabled in order to create revisions from within Panelizer.');
        $form['workflow']['node_options']['panelizer']['#states'] = array(
          'disabled' => array(
            ':input[name="node_options[revision]"]' => array(
              'checked' => FALSE,
            ),
          ),
        );
      }
    }
  }

  /**
   * {@inheritDoc}
   */
  public function add_bundle_setting_form_validate($form, &$form_state, $bundle, $type_location) {

    // Ensure that revisions are enabled if Panelizer revisions are.
    if (isset($form_state['values']['node_options']['panelizer']) || array_key_exists('panelizer', $form_state['values']['node_options'])) {
      $form_state['values']['node_options']['revision'] = 1;
    }
    parent::add_bundle_setting_form_validate($form, $form_state, $bundle, $type_location);
  }
  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++;
          }
        }
      }
    }
  }

  /**
   * Implements a delegated hook_admin_paths.
   */
  public function hook_admin_paths(&$items) {
    if (variable_get('node_admin_theme')) {
      $items['node/*/panelizer*'] = TRUE;
    }
  }
  public function preprocess_panelizer_view_mode(&$vars, $entity, $element, $panelizer, $info) {
    parent::preprocess_panelizer_view_mode($vars, $entity, $element, $panelizer, $info);
    if (!empty($entity->promote)) {
      $vars['classes_array'][] = 'node-promoted';
    }
    if (!empty($entity->sticky)) {
      $vars['classes_array'][] = 'node-sticky';
    }
    if (empty($entity->status)) {
      $vars['classes_array'][] = 'node-unpublished';
    }
  }
  function render_entity($entity, $view_mode, $langcode = NULL, $args = array(), $address = NULL, $extra_contexts = array()) {
    $info = parent::render_entity($entity, $view_mode, $langcode, $args, $address, $extra_contexts);
    if (!empty($info)) {
      if (!empty($entity->promote)) {
        $info['classes_array'][] = 'node-promoted';
      }
      if (!empty($entity->sticky)) {
        $info['classes_array'][] = 'node-sticky';
      }
      if (empty($entity->status)) {
        $info['classes_array'][] = 'node-unpublished';
      }
    }
    return $info;
  }

  /**
   * Implements hook_views_plugins_alter().
   */
  function hook_views_plugins_alter(&$plugins) {

    // While it would be nice to generalize this plugin, there is no generic
    // entity view. This means that to generalize it we'll still need to have
    // each entity know how to do the view individually.
    // @todo make this happen.
    $path = drupal_get_path('module', 'panelizer') . '/plugins/views';
    $plugins['row']['panelizer_node_view'] = array(
      'title' => t('Panelizer display'),
      'help' => t('Render entities using the panels display for any that have been panelized.'),
      'handler' => 'panelizer_plugin_row_panelizer_node_view',
      'parent' => 'node',
      'base' => array(
        'node',
      ),
      'path' => $path,
      'uses options' => TRUE,
      'module' => 'panelizer',
      'type' => 'normal',
      'register theme' => FALSE,
      'name' => 'panelizer_node_view',
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PanelizerEntityDefault::$displays private property Storage for the display defaults already loaded by the system. Used in default_display_exists().
PanelizerEntityDefault::$displays_loaded private property
PanelizerEntityDefault::$enabled_view_modes private property
PanelizerEntityDefault::$entity_type public property The entity type the plugin is for. This is from the $plugin array.
PanelizerEntityDefault::$plugin public property The plugin metadata.
PanelizerEntityDefault::access_admin function
PanelizerEntityDefault::access_default_panelizer_object public function Determine if the current user has access to the $panelizer. Overrides PanelizerEntityInterface::access_default_panelizer_object
PanelizerEntityDefault::add_admin_links public function Helper function to add administrative menu items into an entity's already existing structure.
PanelizerEntityDefault::add_bundle_setting_form public function Add the panelizer settings form to a single entity bundle config form.
PanelizerEntityDefault::add_bundle_setting_form_submit public function Submit callback for the bundle edit form.
PanelizerEntityDefault::admin_bundle_display_path public function Obtain the system path to an entity bundle's display settings page for a specific view mode. Overrides PanelizerEntityInterface::admin_bundle_display_path
PanelizerEntityDefault::check_page_manager_status public function Check if the necessary Page Manager display is enabled and the appropriate variant has not been disabled. Overrides PanelizerEntityInterface::check_page_manager_status
PanelizerEntityDefault::clone_panelizer public function Create a new, scrubbed version of a panelizer object.
PanelizerEntityDefault::default_display_exists public function Determine whether a specific default display object exists. Overrides PanelizerEntityInterface::default_display_exists
PanelizerEntityDefault::delete_entity_panelizer function Delete panelizers associated with the entity.
PanelizerEntityDefault::entity_base_url function Provides the base panelizer URL for an entity.
PanelizerEntityDefault::get_available_view_modes public function Identify the view modes that are available for use with this entity bundle. Overrides PanelizerEntityInterface::get_available_view_modes
PanelizerEntityDefault::get_base_contexts public function Callback to get the base context for a panelized entity Overrides PanelizerEntityInterface::get_base_contexts
PanelizerEntityDefault::get_bundle_title public function
PanelizerEntityDefault::get_contexts public function Fetch an object array of CTools contexts from panelizer information. Overrides PanelizerEntityInterface::get_contexts
PanelizerEntityDefault::get_default_display_default_name public function Determine the default name for the default object. Overrides PanelizerEntityInterface::get_default_display_default_name
PanelizerEntityDefault::get_default_display_name public function Determine the default display name for a given bundle & view mode combination. Overrides PanelizerEntityInterface::get_default_display_name
PanelizerEntityDefault::get_default_display_variable_name public function Determine the variable name used to identify the default display for the given bundle/view mode combination. Overrides PanelizerEntityInterface::get_default_display_variable_name
PanelizerEntityDefault::get_default_panelizer_object public function Load the named default display for the bundle. Overrides PanelizerEntityInterface::get_default_panelizer_object
PanelizerEntityDefault::get_default_panelizer_objects public function Get the default panelizers for the given bundle.
PanelizerEntityDefault::get_enabled_view_modes public function Identify the view modes that are enabled for use with Panelizer. Overrides PanelizerEntityInterface::get_enabled_view_modes
PanelizerEntityDefault::get_entity_view_entity public function Fetch the entity out of a build for hook_entity_view. Overrides PanelizerEntityInterface::get_entity_view_entity 2
PanelizerEntityDefault::get_internal_default_panelizer public function An internal representation of a panelizer object, used to seed when we have none and want something to get started.
PanelizerEntityDefault::get_page_manager_task_name public function Obtain the machine name of the Page Manager task. Overrides PanelizerEntityInterface::get_page_manager_task_name 1
PanelizerEntityDefault::get_substitute public function Identifies a substitute view mode for a given bundle. Overrides PanelizerEntityInterface::get_substitute
PanelizerEntityDefault::get_view_mode public function Identify the view mode that will actually be used for a specific request. Overrides PanelizerEntityInterface::get_view_mode
PanelizerEntityDefault::has_default_panel public function Determine if a bundle has a default display. Overrides PanelizerEntityInterface::has_default_panel
PanelizerEntityDefault::has_panel_choice public function Determine if a bundle is allowed choices. Overrides PanelizerEntityInterface::has_panel_choice
PanelizerEntityDefault::hook_entity_delete public function Overrides PanelizerEntityInterface::hook_entity_delete
PanelizerEntityDefault::hook_entity_insert public function Overrides PanelizerEntityInterface::hook_entity_insert
PanelizerEntityDefault::hook_entity_load public function Overrides PanelizerEntityInterface::hook_entity_load
PanelizerEntityDefault::hook_entity_update public function Overrides PanelizerEntityInterface::hook_entity_update
PanelizerEntityDefault::hook_field_attach_delete_revision public function Overrides PanelizerEntityInterface::hook_field_attach_delete_revision
PanelizerEntityDefault::hook_field_attach_form public function
PanelizerEntityDefault::hook_field_attach_submit public function
PanelizerEntityDefault::hook_menu public function Implements a delegated hook_menu. Overrides PanelizerEntityInterface::hook_menu
PanelizerEntityDefault::hook_menu_alter public function Overrides PanelizerEntityInterface::hook_menu_alter
PanelizerEntityDefault::hook_panelizer_defaults public function Implements a delegated hook_panelizer_defaults().
PanelizerEntityDefault::hook_permission public function Implements a delegated hook_permission. Overrides PanelizerEntityInterface::hook_permission
PanelizerEntityDefault::hook_views_data_alter public function Implement views support for panelizer entity types. Overrides PanelizerEntityInterface::hook_views_data_alter
PanelizerEntityDefault::init function Initialize the plugin and store the plugin info. Overrides PanelizerEntityInterface::init 1
PanelizerEntityDefault::is_page_manager_enabled public function Identify whether page manager is enabled for this entity type. Overrides PanelizerEntityInterface::is_page_manager_enabled 1
PanelizerEntityDefault::is_panelized public function Determine if a bundle is panelized. Overrides PanelizerEntityInterface::is_panelized
PanelizerEntityDefault::load_default_panelizer_objects public function Get the default panels, keyed by names.
PanelizerEntityDefault::make_fake_tabs function Create some fake tabs that are attached to a page output.
PanelizerEntityDefault::page_content function
PanelizerEntityDefault::page_context function
PanelizerEntityDefault::page_layout function
PanelizerEntityDefault::page_overview function Switched page callback to give the overview page
PanelizerEntityDefault::page_reset function Switched page callback to give the settings form.
PanelizerEntityDefault::page_settings function Switched page callback to give the settings form.
PanelizerEntityDefault::panelizer_access function Determine if the user has access to the panelizer operation for this type.
PanelizerEntityDefault::reset_entity_panelizer function Reset displays so that the defaults can be used instead.
PanelizerEntityDefault::settings_form public function Add entity specific form to the Panelizer settings form. Overrides PanelizerEntityInterface::settings_form 1
PanelizerEntityDefault::settings_form_submit public function Submit entity specific settings on the Panelizer settings form. Overrides PanelizerEntityInterface::settings_form_submit
PanelizerEntityDefault::settings_form_validate public function Validate entity specific settings on the Panelizer settings form. Overrides PanelizerEntityInterface::settings_form_validate
PanelizerEntityDefault::wrap_default_panelizer_pages function Provides a wrapper for the panelizer page output.
PanelizerEntityDefault::wrap_entity_panelizer_pages function Provides a wrapper for the panelizer page output.
PanelizerEntityNode::$entity_admin_bundle public property
PanelizerEntityNode::$entity_admin_root public property Where in the entity admin UI we should add Panelizer tabs with bundles. Overrides PanelizerEntityDefault::$entity_admin_root
PanelizerEntityNode::$supports_revisions public property True if the entity supports revisions. Overrides PanelizerEntityDefault::$supports_revisions
PanelizerEntityNode::$uses_page_manager public property
PanelizerEntityNode::$views_table public property The base table in SQL the entity uses, for views support. Overrides PanelizerEntityDefault::$views_table
PanelizerEntityNode::add_bundle_setting_form_validate public function Validate callback for the bundle edit form. Overrides PanelizerEntityDefault::add_bundle_setting_form_validate
PanelizerEntityNode::entity_access public function Determine if the current user has $op access on the $entity. Overrides PanelizerEntityInterface::entity_access
PanelizerEntityNode::entity_allows_revisions public function Determine if the entity allows revisions. Overrides PanelizerEntityDefault::entity_allows_revisions
PanelizerEntityNode::entity_bundle_label public function Get the name of bundles on the entity. Overrides PanelizerEntityDefault::entity_bundle_label
PanelizerEntityNode::entity_identifier public function Get the visible identifier if the identity. Overrides PanelizerEntityDefault::entity_identifier
PanelizerEntityNode::entity_save public function Implement the save function for the entity. Overrides PanelizerEntityInterface::entity_save
PanelizerEntityNode::get_default_display function Provide a default display for newly panelized entities. Overrides PanelizerEntityDefault::get_default_display
PanelizerEntityNode::hook_admin_paths public function Implements a delegated hook_admin_paths. Overrides PanelizerEntityDefault::hook_admin_paths
PanelizerEntityNode::hook_default_page_manager_handlers public function Implements a delegated hook_page_manager_handlers().
PanelizerEntityNode::hook_form_alter public function Implements a delegated hook_form_alter. Overrides PanelizerEntityDefault::hook_form_alter
PanelizerEntityNode::hook_page_alter public function
PanelizerEntityNode::hook_views_plugins_alter function Implements hook_views_plugins_alter().
PanelizerEntityNode::preprocess_panelizer_view_mode public function Preprocess the entity view mode template. Overrides PanelizerEntityDefault::preprocess_panelizer_view_mode
PanelizerEntityNode::render_entity function Render the panels display for a given panelizer entity. Overrides PanelizerEntityDefault::render_entity