function hook_menu(&$items) { // Change the item to a tab. $this->plugin['menu']['items']['list']['type'] = MENU_LOCAL_TASK; $this->plugin['menu']['items']['list']['weight'] = -6; $this->plugin['menu']['items']['list']['title'] = 'List defaults'; // menu local actions are weird. $this->plugin['menu']['items']['add']['path'] = 'list/add'; $this->plugin['menu']['items']['import']['path'] = 'list/import'; // Edit is being handled elsewhere. unset($this->plugin['menu']['items']['edit callback']); unset($this->plugin['menu']['items']['access']); foreach (panelizer_operations() as $path => $operation) { $location = isset($operation['ui path']) ? $operation['ui path'] : $path; if (isset($this->plugin['menu']['items'][$location])) { unset($this->plugin['menu']['items'][$location]); } } // Change the callbacks for everything. foreach ($this->plugin['menu']['items'] as $key => $item) { // The item has already been set; continue to next item to avoid shifting // items onto the page arguments array more than once. if ($this->plugin['menu']['items'][$key]['access callback'] == 'panelizer_has_choice_callback') { continue; } $this->plugin['menu']['items'][$key]['access callback'] = 'panelizer_has_choice_callback'; $this->plugin['menu']['items'][$key]['access arguments'] = array(3, 4, ''); $this->plugin['menu']['items'][$key]['page callback'] = 'panelizer_export_ui_switcher_page'; array_unshift($this->plugin['menu']['items'][$key]['page arguments'], 4); array_unshift($this->plugin['menu']['items'][$key]['page arguments'], 3); } parent::hook_menu($items); }
/** * Add entity specific form to the Panelizer settings form. * * This is primarily to allow bundle selection per entity type. */ public function settings_form(&$form, &$form_state) { // Add entity settings // @todo change theme function name $form['entities'][$this->entity_type] = array('#theme' => 'panelizer_settings_page_table', '#header' => array(array('data' => $this->entity_bundle_label(), 'style' => 'white-space:nowrap;'), t('Panelize'), t('Substitute view mode'), t('Provide initial display'), t('Allow panel choice'), t('Default panel'), t('Update existing entities to use this display'), array('data' => t('Operations'), 'style' => 'white-space:nowrap;')), '#columns' => array('title', 'status', 'substitute', 'default', 'choice', 'selection', 'default revert', 'links')); $entity_info = entity_get_info($this->entity_type); $bundles = $entity_info['bundles']; drupal_alter('panelizer_default_types', $bundles, $this->entity_type); foreach ($bundles as $bundle => $bundle_info) { $view_mode_settings = array(); if (!empty($bundle)) { $view_mode_settings = field_view_mode_settings($this->entity_type, $bundle); } $base_url = 'admin/structure/panelizer/' . $this->entity_type . '/' . $bundle; $bundle_id = str_replace(array('][', '_', ' '), '-', '#edit-entities-' . $this->entity_type . '-' . $bundle . '-0'); // Add the widgets that apply only to the bundle. $form['entities'][$this->entity_type][$bundle][0]['title'] = array('#markup' => '<strong>' . $bundle_info['label'] . '</strong>'); $form['entities'][$this->entity_type][$bundle][0]['status'] = array('#type' => 'checkbox', '#title' => t('Panelize: @label', array('@label' => $bundle_info['label'])), '#title_display' => 'invisible', '#default_value' => !empty($this->plugin['bundles'][$bundle]['status'])); $form['entities'][$this->entity_type][$bundle][0]['help'] = array('#type' => 'hidden', '#default_value' => !empty($this->plugin['bundles'][$bundle]['help']) ? $this->plugin['bundles'][$bundle]['help'] : ''); // Set proper allowed content link for entire bundle based on status if (!empty($this->plugin['bundles'][$bundle]['status'])) { $links_array = array(); if (!empty($bundle_info['admin']['real path'])) { $links_array['displays'] = array('title' => t('manage display'), 'href' => $bundle_info['admin']['real path'] . '/display'); } $links_array['settings'] = array('title' => t('allowed content'), 'href' => $base_url . '/allowed'); $links = theme('links', array('links' => $links_array, 'attributes' => array('class' => array('links', 'inline')))); } else { $links = t('Save to access allowed content'); } $form['entities'][$this->entity_type][$bundle][0]['links']['basic'] = array('#type' => 'item', '#title' => $links, '#states' => array('show' => array($bundle_id . '-status' => array('checked' => TRUE)))); $view_modes = $this->get_available_view_modes($bundle); foreach ($view_modes as $view_mode => $view_mode_label) { $view_mode_info = $this->plugin['view modes'][$view_mode]; $base_id = str_replace(array('][', '_', ' '), '-', '#edit-entities-' . $this->entity_type . '-' . $bundle . '-' . $view_mode); $base_url = 'admin/structure/panelizer/' . $this->entity_type . '/' . $bundle . '.' . $view_mode; if (!empty($this->plugin['bundles'][$bundle]['view modes'][$view_mode]) && is_array($this->plugin['bundles'][$bundle]['view modes'][$view_mode])) { $settings = $this->plugin['bundles'][$bundle]['view modes'][$view_mode]; } else { $settings = array('status' => FALSE, 'default' => FALSE, 'choice' => FALSE); } if (empty($view_mode_info['panelizer special'])) { $form['entities'][$this->entity_type][$bundle][$view_mode]['title'] = array('#markup' => ' ' . $view_mode_label); } else { $form['entities'][$this->entity_type][$bundle][$view_mode]['title'] = array('#markup' => '<strong>' . $bundle_info['label'] . '</strong>'); } $form['entities'][$this->entity_type][$bundle][$view_mode]['status'] = array('#type' => 'checkbox', '#default_value' => !empty($settings['status']), '#title' => t('Panelize: @label, @bundle', array('@label' => $bundle_info['label'], '@bundle' => $view_mode_label)), '#title_display' => 'invisible', '#states' => array('show' => array($bundle_id . '-status' => array('checked' => TRUE)))); $options = array('' => t('- Ignore this option -')) + $view_modes; unset($options[$view_mode]); $form['entities'][$this->entity_type][$bundle][$view_mode]['substitute'] = array('#type' => 'select', '#options' => $options, '#default_value' => $this->get_substitute($view_mode, $bundle), '#title' => t('Substitute view mode: @label, @bundle', array('@label' => $bundle_info['label'], '@bundle' => $view_mode_label)), '#title_display' => 'invisible', '#states' => array('show' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE)))); $form['entities'][$this->entity_type][$bundle][$view_mode]['default'] = array('#type' => 'checkbox', '#default_value' => !empty($settings['default']), '#title' => t('Provide initial display: @label, @bundle', array('@label' => $bundle_info['label'], '@bundle' => $view_mode_label)), '#title_display' => 'invisible', '#states' => array('show' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE), $base_id . '-substitute' => array('value' => '')))); $form['entities'][$this->entity_type][$bundle][$view_mode]['choice'] = array('#type' => 'checkbox', '#default_value' => !empty($settings['choice']), '#title' => t('Allow panel choice: @label, @bundle', array('@label' => $bundle_info['label'], '@bundle' => $view_mode_label)), '#title_display' => 'invisible', '#states' => array('show' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE), $base_id . '-substitute' => array('value' => '')))); // Obtain a list of all available panels for this view mode / bundle. $panelizers = $this->get_default_panelizer_objects($bundle . '.' . $view_mode); $options = array(); if (!empty($panelizers)) { foreach ($panelizers as $name => $panelizer) { // Don't show disabled displays. if (empty($panelizer->disabled)) { $options[$name] = $panelizer->title; } } } if (!empty($options)) { ksort($options); } // The default display to be used if nothing found. $default_name = implode(':', array($this->entity_type, $bundle, 'default')); $variable_name = 'panelizer_' . $this->entity_type . ':' . $bundle . ':' . $view_mode . '_selection'; if ($view_mode != 'page_manager') { $default_name .= ':' . $view_mode; } // If this has not been set previously, use the 'default' as the default // selection. $default_value = variable_get($variable_name, FALSE); if (empty($default_value)) { $default_value = $default_name; } // First time this is displayed there won't be any defaults assigned, so // show a placeholder indicating the page needs to be saved before they // will show. if (count($options) == 0) { if ($default_value == $default_name) { $options = array('' => t('Save to access selector')); } else { $options = array('' => t('No displays created yet')); } } // Indicate which item is actually the default. if (count($options) > 1 && isset($options[$default_value])) { $options[$default_value] .= ' (' . t('default') . ')'; } $form['entities'][$this->entity_type][$bundle][$view_mode]['selection'] = array('#type' => 'select', '#options' => $options, '#default_value' => $default_value, '#title' => t('Default panel: @label, @bundle', array('@label' => $bundle_info['label'], '@bundle' => $view_mode_label)), '#title_display' => 'invisible', '#states' => array('show' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE), $base_id . '-substitute' => array('value' => ''))), '#disabled' => count($options) == 1); $form['entities'][$this->entity_type][$bundle][$view_mode]['default revert'] = array('#type' => 'checkbox', '#default_value' => FALSE, '#title' => t('Update existing entities to use this display: @label, @bundle', array('@label' => $bundle_info['label'], '@bundle' => $view_mode_label)), '#title_display' => 'invisible', '#states' => array('show' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE), $base_id . '-substitute' => array('value' => ''))), '#disabled' => count($options) == 1); $form['entities'][$this->entity_type][$bundle][$view_mode]['links'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>'); // Panelize is enabled and a default display will be provided. if (!empty($settings['status']) && !empty($settings['default']) && empty($settings['choice'])) { $links_array = array(); foreach (panelizer_operations() as $path => $operation) { $links_array[$path] = array('title' => $operation['link title'], 'href' => $base_url . '/' . $path); } $links = theme('links', array('links' => $links_array, 'attributes' => array('class' => array('links', 'inline')))); } else { $links = t('Save to access default panel'); } $form['entities'][$this->entity_type][$bundle][$view_mode]['links']['default'] = array('#type' => 'item', '#title' => $links, '#states' => array('show' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE), $base_id . '-default' => array('checked' => TRUE), $base_id . '-choice' => array('checked' => FALSE), $base_id . '-substitute' => array('value' => '')))); if (!empty($settings['status']) && !empty($settings['choice'])) { $links_array = array('list' => array('title' => t('list'), 'href' => $base_url . '/list')); $links = theme('links', array('links' => $links_array, 'attributes' => array('class' => array('links', 'inline')))); } else { $links = t('Save to access display list'); } $form['entities'][$this->entity_type][$bundle][$view_mode]['links']['default2'] = array('#type' => 'item', '#title' => $links, '#states' => array('show' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE), $base_id . '-choice' => array('checked' => TRUE), $base_id . '-substitute' => array('value' => '')))); // Additional messages if this display is enabled. if (empty($form_state['input']) && $view_mode == 'page_manager' && !empty($settings['status'])) { $this->check_page_manager_status(); } } } $form['#attached'] = array('js' => array(ctools_attach_js('states-show'))); }
/** * Add entity specific form to the Panelizer settings form. * * This is primarily to allow bundle selection per entity type. */ public function settings_form(&$form, &$form_state) { // Add entity settings // @todo change theme function name $form['entities'][$this->entity_type] = array('#theme' => 'panelizer_settings_page_table', '#header' => array(array('data' => $this->entity_bundle_label(), 'width' => '15%'), t('Panelize'), t('Provide default panel'), t('Allow panel choice'), array('data' => t('Operations'), 'width' => '50%')), '#columns' => array('title', 'status', 'default', 'choice', 'links')); $entity_info = entity_get_info($this->entity_type); $bundles = $entity_info['bundles']; drupal_alter('panelizer_default_types', $bundles, $this->entity_type); foreach ($bundles as $bundle => $bundle_info) { $base_url = 'admin/config/content/panelizer/' . $this->entity_type . '/' . $bundle; $bundle_id = str_replace(array('][', '_', ' '), '-', '#edit-entities-' . $this->entity_type . '-' . $bundle . '-0'); // Add the widgets that apply only to the bundle. $form['entities'][$this->entity_type][$bundle][0]['title'] = array('#markup' => '<strong>' . $bundle_info['label'] . '</strong>'); $form['entities'][$this->entity_type][$bundle][0]['status'] = array('#type' => 'checkbox', '#default_value' => !empty($this->plugin['bundles'][$bundle]['status'])); // Set proper allowed content link for entire bundle based on status if (!empty($this->plugin['bundles'][$bundle]['status'])) { $links_array = array('settings' => array('title' => t('allowed content'), 'href' => $base_url . '/allowed')); $links = theme('links', array('links' => $links_array, 'attributes' => array('class' => array('links', 'inline')))); } else { $links = t('Save to access allowed content'); } $form['entities'][$this->entity_type][$bundle][0]['links']['basic'] = array('#type' => 'item', '#title' => $links, '#states' => array('visible' => array($bundle_id . '-status' => array('checked' => TRUE)))); foreach ($this->plugin['view modes'] as $view_mode => $view_mode_info) { $base_id = str_replace(array('][', '_', ' '), '-', '#edit-entities-' . $this->entity_type . '-' . $bundle . '-' . $view_mode); $base_url = 'admin/config/content/panelizer/' . $this->entity_type . '/' . $bundle . '.' . $view_mode; if (!empty($this->plugin['bundles'][$bundle]['view modes'][$view_mode]) && is_array($this->plugin['bundles'][$bundle]['view modes'][$view_mode])) { $settings = $this->plugin['bundles'][$bundle]['view modes'][$view_mode]; } else { $settings = array('status' => FALSE, 'default' => FALSE, 'choice' => FALSE); } if (empty($view_mode_info['panelizer special'])) { $form['entities'][$this->entity_type][$bundle][$view_mode]['title'] = array('#markup' => ' ' . $view_mode_info['label']); } else { $form['entities'][$this->entity_type][$bundle][$view_mode]['title'] = array('#markup' => '<strong>' . $bundle_info['label'] . '</strong>'); } $form['entities'][$this->entity_type][$bundle][$view_mode]['status'] = array('#type' => 'checkbox', '#default_value' => !empty($settings['status']), '#states' => array('visible' => array($bundle_id . '-status' => array('checked' => TRUE)))); $form['entities'][$this->entity_type][$bundle][$view_mode]['default'] = array('#type' => 'checkbox', '#default_value' => !empty($settings['default']), '#states' => array('visible' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE)))); $form['entities'][$this->entity_type][$bundle][$view_mode]['choice'] = array('#type' => 'checkbox', '#default_value' => !empty($settings['choice']), '#states' => array('visible' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE)))); $form['entities'][$this->entity_type][$bundle][$view_mode]['links'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>'); // Panelize is enabled and a default panel will be provided if (!empty($settings['status']) && !empty($settings['default']) && empty($settings['choice'])) { $links_array = array(); foreach (panelizer_operations() as $path => $operation) { $links_array[$path] = array('title' => $operation['link title'], 'href' => $base_url . '/' . $path); } $links = theme('links', array('links' => $links_array, 'attributes' => array('class' => array('links', 'inline')))); } else { $links = t('Save to access default panel'); } $form['entities'][$this->entity_type][$bundle][$view_mode]['links']['default'] = array('#type' => 'item', '#title' => $links, '#states' => array('visible' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE), $base_id . '-default' => array('checked' => TRUE), $base_id . '-choice' => array('checked' => FALSE)))); if (!empty($settings['status']) && !empty($settings['choice'])) { $links_array = array('list' => array('title' => t('list'), 'href' => $base_url . '/list')); $links = theme('links', array('links' => $links_array, 'attributes' => array('class' => array('links', 'inline')))); } else { $links = t('Save to access panel list'); } $form['entities'][$this->entity_type][$bundle][$view_mode]['links']['default2'] = array('#type' => 'item', '#title' => $links, '#states' => array('visible' => array($bundle_id . '-status' => array('checked' => TRUE), $base_id . '-status' => array('checked' => TRUE), $base_id . '-choice' => array('checked' => TRUE)))); } } }