/** * Provide a default display for newly panelized entities. * * This should be implemented by the entity plugin. */ function get_default_display($bundle, $view_mode) { // This is a straight up empty display. $display = panels_new_display(); $display->layout = 'flexible'; $panes = array(); foreach (field_info_instances($this->entity_type, $bundle) as $field_name => $instance) { $view_mode_settings = field_view_mode_settings($this->entity_type, $bundle); $actual_mode = !empty($view_mode_settings[$view_mode]['custom_settings']) ? $view_mode : 'default'; $field_display = $instance['display'][$actual_mode]; $pane = panels_new_pane('entity_field', $this->entity_type . ':' . $field_name, TRUE); $pane->configuration['formatter'] = $field_display['type']; $pane->configuration['formatter_settings'] = $field_display['settings']; $pane->configuration['label'] = $field_display['label']; $pane->configuration['context'] = 'panelizer'; $panes[] = array('#pane' => $pane, '#weight' => $field_display['weight']); } // Use our #weights to sort these so they appear in whatever order the // normal field configuration put them in. uasort($panes, 'element_sort'); foreach ($panes as $pane) { $display->add_pane($pane['#pane'], 'center'); } return $display; }
/** * 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'))); }
public static function getViewModeOptions($entity_type, $bundle = NULL, $include_disabled = TRUE) { $view_modes = array(); $info = entity_get_info($entity_type); if (!empty($info['fieldable'])) { $view_modes['default'] = t('Default'); } if (!empty($info['view modes'])) { $view_modes += ArrayHelper::extractNestedValuesToArray($info['view modes'], array('label')); } // Filter out disabled view modes if requested, and a bundle was provided. if (isset($bundle) && !$include_disabled) { $view_mode_settings = field_view_mode_settings($entity_type, $bundle); foreach ($view_modes as $view_mode => $label) { if (empty($view_mode_settings[$view_mode]['custom_settings'])) { unset($view_modes[$view_mode]); } } } return $view_modes; }