You are here

function fieldable_panels_panes_entity_edit_form in Fieldable Panels Panes (FPP) 7

Basic edit form for the pane entity.

The entity being edited should be stored in $form_state['entity'] when this form is built.

1 call to fieldable_panels_panes_entity_edit_form()
fieldable_panels_panes_fieldable_panels_pane_content_type_edit_form in plugins/content_types/fieldable_panels_pane.inc
Form used to edit our content type.
5 string references to 'fieldable_panels_panes_entity_edit_form'
fieldable_panels_pane::add_entity_page in plugins/export_ui/fieldable_panels_pane.class.php
Add entity page.
fieldable_panels_panes_entities_add_page in includes/admin.inc
Page callback to add a new pane entity.
fieldable_panels_panes_entity_edit_page in includes/admin.inc
Page callback to view a entity.
fieldable_panels_panes_services_create in ./fieldable_panels_panes.services.inc
Adds a new Fieldable Panels Pane and return the fpid.
fieldable_panels_panes_services_update in ./fieldable_panels_panes.services.inc
Updates a Fieldable Panels Pane.

File

./fieldable_panels_panes.module, line 1240
Maintains an entity that appears as panel pane content.

Code

function fieldable_panels_panes_entity_edit_form($form, &$form_state) {
  $entity = $form_state['entity'];

  // Map these properties for entity translations.
  $form['#entity_type'] = array(
    '#type' => 'value',
    '#value' => $entity->bundle,
  );
  $form_state['fieldable_panels_pane'] = $form_state['entity'];
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $entity->title,
    '#weight' => -10,
  );
  if (module_exists('locale')) {
    $form['language'] = array(
      '#type' => 'select',
      '#title' => t('Language'),
      '#default_value' => $entity->language,
      '#options' => array(
        LANGUAGE_NONE => t('Language neutral'),
      ) + locale_language_list('name'),
    );
  }
  else {
    $form['language'] = array(
      '#type' => 'value',
      '#value' => $entity->language,
    );
  }
  $form['link'] = array(
    '#type' => 'container',
    '#states' => array(
      'visible' => array(
        ':input[name="title"]' => array(
          'empty' => FALSE,
        ),
      ),
    ),
  );
  $form['link']['link'] = array(
    '#title' => t('Make title a link'),
    '#type' => 'checkbox',
    '#default_value' => $entity->link,
    '#description' => t('Check here to make the title link to another page.'),
  );
  $form['link']['path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path'),
    '#description' => t('The path for this link. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array(
      '%front' => '<front>',
      '%add-node' => 'node/add',
      '%drupal' => 'http://drupal.org',
    )),
    '#states' => array(
      'visible' => array(
        ':input[name="link"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#default_value' => $entity->path,
    '#maxlength' => 255,
  );
  $form['additional_settings'] = array(
    '#type' => 'vertical_tabs',
    '#weight' => 99,
  );
  $form['admin'] = array(
    '#type' => 'fieldset',
    '#title' => t('Admin'),
    '#collapsible' => TRUE,
    '#collapsed' => empty($entity->admin),
    '#group' => 'additional_settings',
    '#attributes' => array(
      'class' => array(
        'fieldable-pane-pane-form-admin-information',
      ),
    ),
    '#attached' => array(
      'js' => array(
        'vertical-tabs' => drupal_get_path('module', 'fieldable_panels_panes') . '/fieldable_panels_panes.vertical-tabs.js',
      ),
    ),
    '#weight' => 10,
  );
  $form['reusable'] = array(
    '#type' => 'fieldset',
    '#title' => t('Reusability'),
    '#collapsible' => TRUE,
    '#collapsed' => empty($entity->reusable),
    '#group' => 'additional_settings',
    '#attributes' => array(
      'class' => array(
        'fieldable-pane-pane-form-reusable-information',
      ),
    ),
    '#attached' => array(
      'js' => array(
        'vertical-tabs' => drupal_get_path('module', 'fieldable_panels_panes') . '/fieldable_panels_panes.vertical-tabs.js',
      ),
    ),
    '#weight' => 10,
    // Cannot change this after the initial creation, but reusable FPPs can be
    // have their category changed.
    '#access' => empty($entity->fpid) || !empty($entity->fpid) && !empty($entity->reusable),
  );
  $form['reusable']['reusable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Make this entity reusable'),
    '#default_value' => $entity->reusable,
    '#description' => t('A reusable pane may be used multiple times on the same page or on other pages. A non-reusable pane may not be added to another page once it is created and added to this page. This option may not be changed after the pane is created.'),
    // It's dangerous to change an FPP's reusability after it is created, so
    // this is disabled when editing existing FPPs.
    '#disabled' => !empty($entity->fpid),
  );
  $form['reusable']['category'] = array(
    '#type' => 'textfield',
    '#title' => t('Category'),
    '#description' => t('The category this content will appear in the "Add content" modal. If left blank the category will be "Miscellaneous".'),
    '#default_value' => $entity->category,
    '#states' => array(
      'visible' => array(
        ':input[name="reusable"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['admin']['admin_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Administrative title'),
    '#description' => t("Title used for administrative purposes. Used to identify panes within admin pages."),
    '#default_value' => $entity->admin_title,
  );
  $form['admin']['admin_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Administrative description'),
    '#description' => t('A description of what this content is, does or is for, for administrative use.'),
    '#default_value' => $entity->admin_description,
  );
  $form['revision'] = array(
    '#type' => 'fieldset',
    '#title' => t('Revision'),
    '#collapsible' => TRUE,
    '#collapsed' => empty($entity->revision),
    '#group' => 'additional_settings',
    '#attributes' => array(
      'class' => array(
        'fieldable-pane-pane-form-revision-information',
      ),
    ),
    '#attached' => array(
      'js' => array(
        'vertical-tabs' => drupal_get_path('module', 'fieldable_panels_panes') . '/fieldable_panels_panes.vertical-tabs.js',
      ),
    ),
    '#weight' => 30,
    // Don't show the revision options if this is a new FPP.
    '#access' => !empty($entity->fpid),
  );
  $form['revision']['revision'] = array(
    '#type' => 'checkbox',
    '#title' => t('Create new revision'),
    '#default_value' => 1,
  );

  // Force a new revision to be created if the user does not have 'admin FPP'
  // access, or the 'lock' mode was enabled and this is not a reusable FPP.
  if (!user_access('administer fieldable panels panes') || $entity->vid != $entity->current_vid || !empty($entity->fpid) && empty($entity->reusable) && variable_get('fpp_revision_locking', 'lock') == 'lock') {
    $form['revision']['revision']['#disabled'] = TRUE;
    $form['revision']['revision']['#value'] = TRUE;

    // Inform the user that the pane will be locked.
    if (!empty($entity->fpid) && empty($entity->reusable) && variable_get('fpp_revision_locking', 'lock') == 'lock') {
      $form['revision']['revision']['#description'] = t('A new revision will be created because this pane is non-reusable and the locking mode has been enabled.');
    }
  }
  $form['revision']['log'] = array(
    '#type' => 'textarea',
    '#title' => t('Log message'),
    '#description' => t('Provide an explanation of the changes being made.'),
    '#default_value' => '',
    '#states' => array(
      'visible' => array(
        ':input[name="revision"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );

  // Override reusable pane settings to be changed after the pane is created.
  if (variable_get('fpp_allow_reusable_access', FALSE)) {

    // Reset field access.
    unset($form['reusable']['#access']);
    $form['reusable']['reusable']['#description'] = t('A reusable pane may be used multiple times on the same page or on other pages. A non-reusable pane may not be added to another page once it is created and added to this page. Once this option has been checked it cannot be turned off.');
    $form['reusable']['reusable']['#disabled'] = !empty($form_state['entity']->reusable);
  }
  $language = NULL;
  if (function_exists('entity_language')) {

    // entity_language() was added in Drupal 7.15.
    $language = entity_language('fieldable_panels_pane', $entity);
  }
  field_attach_form('fieldable_panels_pane', $entity, $form, $form_state, $language);
  if (!empty($form_state['add submit'])) {
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
    );
  }
  return $form;
}