/** * 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 function hook_field_attach_form($entity, &$form, &$form_state, $langcode) { list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity); // We'll store the form array here so that we can tell at the end if we // have any and need to add our fieldset. $widgets = array(); // Need to track the number of actual visible widgets because // element_get_visible_children doesn't handle nested fields. $visible_widgets = 0; foreach ($this->plugin['view modes'] as $view_mode => $view_mode_info) { $view_bundle = $bundle . '.' . $view_mode; $panelizers = $this->get_default_panelizer_objects($view_bundle); // Ignore view modes that don't have a choice, have no displays defined, // or already have their own custom panel set up. if (!$this->has_panel_choice($view_bundle) || empty($panelizers) || !empty($entity->panelizer[$view_mode]->did)) { continue; } $options = array(); foreach ($panelizers as $name => $panelizer) { if (empty($panelizer->disabled)) { $options[$name] = $panelizer->title ? $panelizer->title : t('Default'); } } // Load the configured default display. $default_value = $this->get_default_display_name($bundle, $view_mode); // The selected value. $selected = $default_value; if (!empty($entity->panelizer[$view_mode]->name)) { $selected = $entity->panelizer[$view_mode]->name; } // Only display the selector if options were available. if (!empty($options)) { // Indicate which item is the default. if (isset($options[$default_value])) { $options[$default_value] .= ' (' . t("default for '@bundle'", array('@bundle' => $bundle)) . ')'; } // If only one option is available, don't show the selector. if (count($options) === 1) { $widgets[$view_mode]['name'] = array('#title' => $view_mode_info['label'], '#type' => 'value', '#value' => $selected, '#revision_id' => isset($entity->panelizer[$view_mode]->revision_id) ? $entity->panelizer[$view_mode]->revision_id : NULL, '#entity_id' => isset($entity->panelizer[$view_mode]->entity_id) ? $entity->panelizer[$view_mode]->entity_id : NULL); } else { $widgets[$view_mode]['name'] = array('#title' => $view_mode_info['label'], '#type' => 'select', '#options' => $options, '#default_value' => $selected, '#required' => TRUE, '#revision_id' => isset($entity->panelizer[$view_mode]->revision_id) ? $entity->panelizer[$view_mode]->revision_id : NULL, '#entity_id' => isset($entity->panelizer[$view_mode]->entity_id) ? $entity->panelizer[$view_mode]->entity_id : NULL); $visible_widgets++; } } } // Only display this if the entity has visible options available. if (!empty($widgets)) { $form_state['panelizer has choice'] = TRUE; $form['panelizer'] = array('#type' => 'fieldset', '#access' => $this->panelizer_access('choice', $entity, $view_mode), '#title' => t('Panelizer'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#group' => 'additional_settings', '#attributes' => array('class' => array('panelizer-entity-options')), '#attached' => array('js' => array(ctools_attach_js('panelizer-vertical-tabs', 'panelizer'))), '#weight' => -10, '#tree' => TRUE) + $widgets; // If there are no visible widgets, don't display the fieldset. if ($visible_widgets == 0) { $form['panelizer']['#access'] = FALSE; } } }
/** * Create the filter/sort form at the top of a list of exports. * * This handles the very default conditions, and most lists are expected * to override this and call through to parent::list_form() in order to * get the base form and then modify it as necessary to add search * gadgets for custom fields. */ function list_form(&$form, &$form_state) { // This forces the form to *always* treat as submitted which is // necessary to make it work. $form['#token'] = FALSE; if (empty($form_state['input'])) { $form["#post"] = TRUE; } // Add the 'q' in if we are not using clean URLs or it can get lost when // using this kind of form. if (!variable_get('clean_url', FALSE)) { $form['q'] = array('#type' => 'hidden', '#value' => $_GET['q']); } $all = array('all' => t('- All -')); $form['top row'] = array('#prefix' => '<div class="ctools-export-ui-row ctools-export-ui-top-row clearfix">', '#suffix' => '</div>'); $form['bottom row'] = array('#prefix' => '<div class="ctools-export-ui-row ctools-export-ui-bottom-row clearfix">', '#suffix' => '</div>'); $form['top row']['storage'] = array('#type' => 'select', '#title' => t('Storage'), '#options' => $all + array(t('Normal') => t('Normal'), t('Default') => t('Default'), t('Overridden') => t('Overridden')), '#default_value' => 'all'); $form['top row']['disabled'] = array('#type' => 'select', '#title' => t('Enabled'), '#options' => $all + array('0' => t('Enabled'), '1' => t('Disabled')), '#default_value' => 'all'); $form['top row']['search'] = array('#type' => 'textfield', '#title' => t('Search')); $form['bottom row']['order'] = array('#type' => 'select', '#title' => t('Sort by'), '#options' => $this->list_sort_options(), '#default_value' => 'disabled'); $form['bottom row']['sort'] = array('#type' => 'select', '#title' => t('Order'), '#options' => array('asc' => t('Up'), 'desc' => t('Down')), '#default_value' => 'asc'); $form['bottom row']['submit'] = array('#type' => 'submit', '#id' => 'ctools-export-ui-list-items-apply', '#value' => t('Apply'), '#attributes' => array('class' => array('use-ajax-submit ctools-auto-submit-click'))); $form['bottom row']['reset'] = array('#type' => 'submit', '#id' => 'ctools-export-ui-list-items-apply', '#value' => t('Reset'), '#attributes' => array('class' => array('use-ajax-submit'))); $form['#prefix'] = '<div class="clearfix">'; $form['#suffix'] = '</div>'; $form['#attached']['js'] = array(ctools_attach_js('auto-submit')); $form['#attached']['library'][] = array('system', 'drupal.ajax'); $form['#attached']['library'][] = array('system', 'jquery.form'); $form['#attributes'] = array('class' => array('ctools-auto-submit-full-form')); }
public function hook_field_attach_form($entity, &$form, &$form_state, $langcode) { list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity); // We'll store the form array here so that we can tell at the end if we // have any and need to add our fieldset. $widgets = array(); foreach ($this->plugin['view modes'] as $view_mode => $view_mode_info) { $view_bundle = $bundle . '.' . $view_mode; // Ignore view modes that don't have a choice or already have their // own custom panel set up. if (!$this->has_panel_choice($view_bundle) || !empty($entity->panelizer[$view_mode]->did)) { continue; } $panelizers = $this->get_default_panelizer_objects($view_bundle); $options = array(); foreach ($panelizers as $name => $panelizer) { if (empty($panelizer->disabled)) { $options[$name] = $panelizer->title ? $panelizer->title : t('Default'); } } if (!empty($entity->panelizer[$view_mode]->name)) { $name = $entity->panelizer[$view_mode]->name; } else { if ($this->has_default_panel($view_bundle)) { $name = implode(':', array($this->entity_type, $bundle, 'default')); if ($view_mode != 'page_manager') { $name .= ':' . $view_mode; } } else { $name = ''; } } if (!$this->has_default_panel($view_bundle)) { $options = array('' => t('-- No panel --')) + $options; } $widgets[$view_mode]['name'] = array('#title' => $view_mode_info['label'], '#type' => 'select', '#options' => $options, '#default_value' => $name, '#revision_id' => isset($entity->panelizer[$view_mode]->revision_id) ? $entity->panelizer[$view_mode]->revision_id : NULL, '#entity_id' => isset($entity->panelizer[$view_mode]->entity_id) ? $entity->panelizer[$view_mode]->entity_id : NULL); } if ($widgets) { $form_state['panelizer has choice'] = TRUE; $form['panelizer'] = array('#type' => 'fieldset', '#access' => $this->panelizer_access('choice', $entity, $view_mode), '#title' => t('Panelizer'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#group' => 'additional_settings', '#attributes' => array('class' => array('panelizer-entity-options')), '#attached' => array('js' => array(ctools_attach_js('panelizer-vertical-tabs', 'panelizer'))), '#weight' => -10, '#tree' => TRUE) + $widgets; } }