You are here

public function PanelizerEntityDefault::hook_field_attach_form in Panelizer 7.2

Same name and namespace in other branches
  1. 7.3 plugins/entity/PanelizerEntityDefault.class.php \PanelizerEntityDefault::hook_field_attach_form()

File

plugins/entity/PanelizerEntityDefault.class.php, line 884
Base class for the Panelizer Entity plugin.

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

public function hook_field_attach_form($entity, &$form, &$form_state, $langcode) {
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);

  // Do not give choices to non panelized nodes, or nodes that already have
  // their won panel.
  if (!$this
    ->has_panel_choice($bundle) || !empty($entity->panelizer->did)) {
    return;
  }
  $form_state['panelizer has choice'] = TRUE;
  $form['panelizer'] = array(
    '#type' => 'fieldset',
    '#access' => $this
      ->panelizer_access('choice', $entity),
    '#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,
    // Put these here because submit does not get a real entity with
    // the actual *(&)ing panelizer.
    '#revision_id' => isset($entity->panelizer->revision_id) ? $entity->panelizer->revision_id : NULL,
    '#entity_id' => isset($entity->panelizer->entity_id) ? $entity->panelizer->entity_id : NULL,
  );
  $panelizers = $this
    ->get_default_panelizer_objects($bundle);
  $options = array();
  foreach ($panelizers as $name => $panelizer) {
    if (empty($panelizer->disabled)) {
      $options[$name] = $panelizer->title ? $panelizer->title : t('Default');
    }
  }
  if (!empty($entity->panelizer->name)) {
    $name = $entity->panelizer->name;
  }
  else {
    if ($this
      ->has_default_panel($bundle)) {
      $name = implode(':', array(
        $this->entity_type,
        $bundle,
        'default',
      ));
    }
    else {
      $name = '';
    }
  }
  if (!$this
    ->has_default_panel($bundle)) {
    $options = array(
      '' => t('-- No panel --'),
    ) + $options;
  }
  $form['panelizer']['name'] = array(
    '#title' => t('Panel'),
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => $name,
  );
}