You are here

function panelizer_form_alter in Panelizer 7.3

Same name and namespace in other branches
  1. 7.2 panelizer.module \panelizer_form_alter()

Implements hook_form_alter().

File

./panelizer.module, line 216
The Panelizer module attaches panels to entities, providing default panels and allowing each panel to be configured independently by privileged users.

Code

function panelizer_form_alter(&$form, &$form_state, $form_id) {

  // Delegate.
  foreach (panelizer_get_plugins_with_hook('form_alter') as $handler) {
    $handler
      ->hook_form_alter($form, $form_state, $form_id);

    // Support default content and layout settings.
    foreach ($handler->plugin['bundles'] as $bundle_name => $bundle) {
      if ($form_id == 'panels_common_settings' && $form_state['build_info']['args'][0] == 'panelizer_' . $handler->entity_type . ':' . $bundle_name) {

        // Provide settings for the default content and layout options.
        $form['default_settings'] = array(
          '#type' => 'fieldset',
          '#title' => t('Default settings'),
          '#group' => 'additional_settings',
          '#weight' => -20,
        );
        $form['default_settings']['default_content_settings'] = array(
          '#title' => t('Use the same allowed content as standard Panels pages?'),
          '#type' => 'checkbox',
          '#default_value' => variable_get($form_state['build_info']['args'][0] . '_allowed_types_default', FALSE),
        );
        $form['default_settings']['default_layout_settings'] = array(
          '#title' => t('Use the same allowed  layouts as standard Panels pages?'),
          '#type' => 'checkbox',
          '#default_value' => variable_get($form_state['build_info']['args'][0] . '_allowed_layouts_default', FALSE),
        );

        // Disable the layout options when the default layout setting is enabled
        if (!empty($form['layout_selection']['layouts']) && variable_get($form_state['build_info']['args'][0] . '_allowed_layouts_default', FALSE)) {
          $form['layout_selection']['layouts']['#disabled'] = TRUE;
        }

        // Disable the content options when the default content setting is
        // enabled.
        if (variable_get($form_state['build_info']['args'][0] . '_allowed_types_default', FALSE)) {
          $content_types = ctools_content_get_all_types();
          $content_types['other'] = array(
            'title' => t('Other'),
            'weight' => 10,
          );
          foreach ($content_types as $content_type => $content_type_value) {
            if (!empty($form['content_types'][$content_type]['options'])) {
              $form['content_types'][$content_type]['options']['#disabled'] = TRUE;
            }
          }
          $form['common']['panels_common_default']['#disabled'] = TRUE;
        }
        $form['#submit'][] = 'panelizer_panels_default_settings_submit';
      }
    }
  }
}