public function PanelizerEntityDefault::add_bundle_setting_form in Panelizer 7.3
Same name and namespace in other branches
- 7.2 plugins/entity/PanelizerEntityDefault.class.php \PanelizerEntityDefault::add_bundle_setting_form()
Add the panelizer settings form to a single entity bundle config form.
Parameters
&$form: The form array.
&$form_state: The form state array.
$bundle: The machine name of the bundle this form is for.
$type_location: The location in the form state values that the bundle name will be; this is used so that if a machine name of a bundle is changed, Panelizer can update as much as possible.
3 calls to PanelizerEntityDefault::add_bundle_setting_form()
- PanelizerEntityNode::hook_form_alter in plugins/
entity/ PanelizerEntityNode.class.php - Implements a delegated hook_form_alter.
- PanelizerEntityTaxonomyTerm::hook_form_alter in plugins/
entity/ PanelizerEntityTaxonomyTerm.class.php - Implements a delegated hook_form_alter.
- PanelizerEntityUser::hook_form_alter in plugins/
entity/ PanelizerEntityUser.class.php - Implements a delegated hook_form_alter.
File
- plugins/
entity/ PanelizerEntityDefault.class.php, line 922 - Base class for the Panelizer Entity plugin.
Class
- PanelizerEntityDefault
- Base class for the Panelizer Entity plugin.
Code
public function add_bundle_setting_form(&$form, &$form_state, $bundle, $type_location) {
$settings = !empty($this->plugin['bundles'][$bundle]) ? $this->plugin['bundles'][$bundle] : array(
'status' => FALSE,
'choice' => FALSE,
);
$entity_info = entity_get_info($this->entity_type);
$perms_url = url('admin/people/permissions');
$manage_display = t('Manage Display');
$bundle_info = array();
if (isset($entity_info['bundles'][$bundle])) {
$bundle_info = $entity_info['bundles'][$bundle];
if (!empty($bundle_info['admin']['real path'])) {
$manage_display = l($manage_display, $bundle_info['admin']['real path'] . '/display');
}
}
$view_mode_settings = array();
if (!empty($bundle)) {
$view_mode_settings = field_view_mode_settings($this->entity_type, $bundle);
}
$form['panelizer'] = array(
'#type' => 'fieldset',
'#title' => t('Panelizer'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#group' => 'additional_settings',
'#attributes' => array(
'class' => array(
'panelizer-entity-bundle',
),
),
'#bundle' => $bundle,
'#location' => $type_location,
'#tree' => TRUE,
'#access' => panelizer_administer_entity_bundle($this, $bundle),
'#attached' => array(
'js' => array(
ctools_attach_js('panelizer-entity-bundle', 'panelizer'),
),
),
);
// The master checkbox.
$form['panelizer']['status'] = array(
'#title' => t('Panelize'),
'#type' => 'checkbox',
'#default_value' => !empty($settings['status']),
'#id' => 'panelizer-status',
'#description' => t('Allow content of this type to have its display controlled by Panelizer. Once enabled, each individual view mode will have further options and will add <a href="!perm_url">several new permissions</a>.', array(
'!perm_url' => $perms_url,
)) . '<br />' . t('Other than "Full page override" and "Default", only view modes enabled through the Custom Display Settings section of the !manage_display tab will be available for use.', array(
'!manage_display' => $manage_display,
)) . '<br />' . t('Once enabled, a new tab named "Customize display" will show on pages for this content.'),
);
// Help, I need somebody.
$form['panelizer']['help'] = array(
'#title' => t('Optional help message to show above the display selector, if applicable'),
'#type' => 'textarea',
'#rows' => 3,
'#default_value' => !empty($settings['help']) ? $settings['help'] : '',
'#id' => 'panelizer-help',
'#description' => t('Only used if one or more of the view modes has a display that allows multiple values and the "Customize display" tab is to be shown on the entity edit form. Allows HTML.'),
'#states' => array(
'visible' => array(
'#panelizer-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];
$form['panelizer']['view modes'][$view_mode] = array(
'#type' => 'item',
// '#title' => '<hr />' . $view_mode_info['label'],
'#states' => array(
'visible' => array(
'#panelizer-status' => array(
'checked' => TRUE,
),
),
),
);
// Show the optional view mode description.
$pm_links = array(
'!pm' => l('Page Manager', 'admin/structure/pages'),
'!panels' => l('Panels', 'admin/structure/panels'),
'!entity_type' => $this->entity_type,
'!task_name' => $this
->get_page_manager_task_name(),
);
$description = '';
if ($view_mode == 'default') {
$description = t('If a requested view mode for an entity was not enabled in the !manage_display tab page, this view mode will be used as a failover. For example, if "Teaser" was being used but it was not enabled.', array(
'!manage_display' => $manage_display,
));
}
elseif ($view_mode == 'page_manager') {
$description = t("A custom view mode only used when !pm/!panels is used to control this entity's full page display, i.e. the '!task_name' display is enabled. Unlike the \"!full\" view mode, this one allows customization of the page title.", $pm_links + array(
'!full' => !empty($entity_info['view modes']['full']['label']) ? $entity_info['view modes']['full']['label'] : 'Full',
));
}
elseif ($view_mode == 'full') {
$description = t('Used when viewing !entity_type entities on their standalone page, does not allow customization of the page title.', array(
'!entity_type' => $this->entity_type,
));
}
elseif ($view_mode == 'teaser') {
$description = t('Used in content lists by default, e.g. on the default homepage and on taxonomy term pages.');
}
elseif ($view_mode == 'rss') {
$description = t('Used by the default RSS content lists.');
}
$form['panelizer']['view modes'][$view_mode]['status'] = array(
'#title' => $view_mode_info['label'],
'#type' => 'checkbox',
'#default_value' => !empty($settings['view modes'][$view_mode]['status']),
'#id' => 'panelizer-' . $view_mode . '-status',
'#prefix' => '<hr />',
'#description' => $description,
'#attributes' => array(
'title' => $view_mode_info['label'],
),
'#states' => array(
'visible' => array(
'#panelizer-status' => array(
'checked' => TRUE,
),
),
),
);
if ($view_mode == 'page_manager') {
if (!$this
->is_page_manager_enabled()) {
$form['panelizer']['view modes'][$view_mode]['status']['#title'] .= ' (<em>' . t('!pm is enabled correctly', $pm_links) . '</em>)';
}
else {
$form['panelizer']['view modes'][$view_mode]['status']['#title'] .= ' (<em>' . t('"!task_name" must be enabled in !pm', $pm_links) . '</em>)';
// Only display this message if the form has not been submitted, the
// bundle has been panelized and the view mode is panelized.
if (empty($form_state['input']) && !empty($settings['status']) && !empty($settings['view modes'][$view_mode]['status'])) {
drupal_set_message(t('Note: "!task_name" display must be enabled in !pm in order for the !entity_type full page display ("Full page override") to work correctly.', $pm_links), 'warning', FALSE);
}
}
}
$options = array(
'' => t('- Ignore this option -'),
) + $view_modes;
unset($options[$view_mode]);
$form['panelizer']['view modes'][$view_mode]['substitute'] = array(
'#title' => t('Substitute a different view mode in place of this one'),
'#description' => t("Allows this view mode to be enabled but for the actual display to be handled by another view mode. This can save on configuration effort should multiple view modes need to look the same."),
'#type' => 'select',
'#options' => $options,
'#default_value' => $this
->get_substitute($view_mode, $bundle),
'#id' => 'panelizer-' . $view_mode . '-substitute',
'#states' => array(
'visible' => array(
'#panelizer-status' => array(
'checked' => TRUE,
),
'#panelizer-' . $view_mode . '-status' => array(
'checked' => TRUE,
),
),
),
);
$form['panelizer']['view modes'][$view_mode]['default'] = array(
'#title' => t('Provide an initial display named "Default"'),
'#type' => 'checkbox',
'#default_value' => !empty($settings['view modes'][$view_mode]['status']) && !empty($settings['view modes'][$view_mode]['default']),
'#id' => 'panelizer-' . $view_mode . '-initial',
'#states' => array(
'visible' => array(
'#panelizer-status' => array(
'checked' => TRUE,
),
'#panelizer-' . $view_mode . '-status' => array(
'checked' => TRUE,
),
'#panelizer-' . $view_mode . '-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;
}
// Indicate which item is actually the default.
if (count($options) > 1 && isset($options[$default_value])) {
$options[$default_value] .= ' (' . t('default') . ')';
}
if (!empty($bundle_info) && count($options) > 0) {
$form['panelizer']['view modes'][$view_mode]['selection'] = array(
'#title' => t('Default panel'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $default_value,
'#id' => 'panelizer-' . $view_mode . '-default',
'#states' => array(
'visible' => array(
'#panelizer-status' => array(
'checked' => TRUE,
),
'#panelizer-' . $view_mode . '-status' => array(
'checked' => TRUE,
),
'#panelizer-' . $view_mode . '-substitute' => array(
'value' => '',
),
),
),
'#required' => count($options),
'#disabled' => count($options) == 0,
'#description' => t('The default display to be used for new %bundle records. If "Allow panel choice" is not enabled, the item selected will be used for any new %bundle record. All existing %bundle records will have to be manually updated to the new selection.', array(
'%bundle' => $bundle,
)),
);
$form['panelizer']['view modes'][$view_mode]['default revert'] = array(
'#type' => 'checkbox',
'#title' => t('Update existing entities to use this display'),
'#states' => array(
'visible' => array(
'#panelizer-status' => array(
'checked' => TRUE,
),
'#panelizer-' . $view_mode . '-status' => array(
'checked' => TRUE,
),
'#panelizer-' . $view_mode . '-substitute' => array(
'value' => '',
),
),
),
'#description' => t('Will update all %bundle records to use the newly selected display, unless they have been customized. Note: only takes effect when the display is changed, and will not work if the default was not assigned previously.', array(
'%bundle' => $bundle,
)),
'#field_prefix' => ' ',
);
}
// Control whether the default can be selected.
$form['panelizer']['view modes'][$view_mode]['choice'] = array(
'#title' => t('Allow per-record display choice'),
'#type' => 'checkbox',
'#default_value' => !empty($settings['view modes'][$view_mode]['status']) && !empty($settings['view modes'][$view_mode]['choice']),
'#id' => 'panelizer-' . $view_mode . '-choice',
'#states' => array(
'visible' => array(
'#panelizer-status' => array(
'checked' => TRUE,
),
'#panelizer-' . $view_mode . '-status' => array(
'checked' => TRUE,
),
'#panelizer-' . $view_mode . '-substitute' => array(
'value' => '',
),
),
),
'#description' => t("Allows multiple displays to be created for this view mode. Once created, a selector will be provided on the %bundle record's edit form allowing the display of this view mode to be chosen. Additionally, any customizations made will be based upon the selected display. Note: the selector will not be shown if there is only one display, instead the default will be automatically selected.", array(
'%bundle' => $bundle,
)),
);
if (!empty($bundle)) {
$form['panelizer']['view modes'][$view_mode]['choice']['#description'] .= '<br />' . t('This option adds a <a href="!perm_url">new permission</a>: !perm', array(
'!perm_url' => $perms_url,
'!perm' => t('%entity_name %bundle_name: Choose panels', array(
'%entity_name' => $entity_info['label'],
'%bundle_name' => $entity_info['bundles'][$bundle]['label'],
)),
));
}
}
array_unshift($form['#validate'], 'panelizer_entity_default_bundle_form_validate');
array_unshift($form['#submit'], 'panelizer_entity_default_bundle_form_submit');
$form_state['panelizer_entity_handler'] = $this;
}