You are here

class EntityReferencePrepopulateInstanceBehavior in Entityreference prepopulate 7

Hierarchy

Expanded class hierarchy of EntityReferencePrepopulateInstanceBehavior

1 string reference to 'EntityReferencePrepopulateInstanceBehavior'
prepopulate.inc in plugins/behavior/prepopulate.inc

File

plugins/behavior/EntityReferencePrepopulateInstanceBehavior.class.php, line 3

View source
class EntityReferencePrepopulateInstanceBehavior extends EntityReference_BehaviorHandler_Abstract {

  /**
   * Generate a settings form for this handler.
   */
  public function settingsForm($field, $instance) {
    $form['action'] = array(
      '#type' => 'select',
      '#title' => t('Action'),
      '#options' => array(
        'none' => t('Do nothing'),
        'hide' => t('Hide field'),
        'disable' => t('Disable field'),
      ),
      '#description' => t('Action to take when prepopulating field with values via URL.'),
    );
    $form['action_on_edit'] = array(
      '#type' => 'checkbox',
      '#title' => t('Apply action on edit'),
      '#description' => t('Apply action when editing an existing entity.'),
      '#states' => array(
        'invisible' => array(
          ':input[name="instance[settings][behaviors][prepopulate][action]"]' => array(
            'value' => 'none',
          ),
        ),
      ),
    );
    $form['fallback'] = array(
      '#type' => 'select',
      '#title' => t('Fallback behaviour'),
      '#description' => t('Determine what should happen if no values are provided via URL.'),
      '#options' => array(
        'none' => t('Do nothing'),
        'hide' => t('Hide field'),
        'form_error' => t('Set form error'),
        'redirect' => t('Redirect'),
      ),
    );

    // Get list of permissions.
    $perms = array();
    $perms[0] = t('- None -');
    foreach (module_list(FALSE, FALSE, TRUE) as $module) {

      // By keeping them keyed by module we can use optgroups with the
      // 'select' type.
      if ($permissions = module_invoke($module, 'permission')) {
        foreach ($permissions as $id => $permission) {
          $perms[$module][$id] = strip_tags($permission['title']);
        }
      }
    }
    $form['skip_perm'] = array(
      '#type' => 'select',
      '#title' => t('Skip access permission'),
      '#description' => t('Set a permission that will not be affected by the fallback behavior.'),
      '#options' => $perms,
    );
    $form['identifier'] = array(
      '#type' => 'textfield',
      '#title' => t('Identifier'),
      '#description' => t('Field identifier in the URL, defaults to the field name if left blank. i.e. @field_name', array(
        '@field_name' => $field['field_name'],
      )),
    );
    $form['providers'] = array(
      '#type' => 'container',
      '#theme' => 'entityreference_prepopulate_providers_table',
      '#element_validate' => array(
        'entityreference_prepopulate_providers_validate',
      ),
    );
    $providers = entityreference_prepopulate_providers_info();

    // Sort providers by weight.
    $providers_names = !empty($instance['settings']['behaviors']['prepopulate']['providers']) ? array_keys($instance['settings']['behaviors']['prepopulate']['providers']) : array();
    $providers_names = drupal_array_merge_deep($providers_names, array_keys($providers));
    $weight = 0;
    foreach ($providers_names as $name) {

      // Validate that the provider exists.
      if (!isset($providers[$name])) {
        continue;
      }
      $provider = $providers[$name];

      // Set default values.
      $provider += array(
        'disabled' => FALSE,
      );
      $form['providers']['title'][$name] = array(
        '#type' => 'item',
        '#markup' => filter_xss($provider['title']),
        '#description' => filter_xss($provider['description']),
      );
      if (!isset($instance['settings']['behaviors']['prepopulate']['providers'][$name])) {

        // backwards compatibility with version 1.4.
        if ($name == 'url') {

          // Enable the URL provider is it is not set in the instance yet.
          $default_value = TRUE;
        }
        elseif ($name == 'og_context') {
          $default_value = !empty($instance['settings']['behaviors']['prepopulate']['og_context']);
        }
      }
      else {
        $default_value = !empty($instance['settings']['behaviors']['prepopulate']['providers'][$name]);
      }
      $form['providers']['enabled'][$name] = array(
        '#type' => 'checkbox',
        '#disabled' => $provider['disabled'],
        '#default_value' => $default_value,
      );
      $form['providers']['weight'][$name] = array(
        '#type' => 'weight',
        '#default_value' => $weight,
        '#attributes' => array(
          'class' => array(
            'provider-weight',
          ),
        ),
      );
      ++$weight;
    }
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityReferencePrepopulateInstanceBehavior::settingsForm public function Generate a settings form for this handler. Overrides EntityReference_BehaviorHandler_Abstract::settingsForm
EntityReference_BehaviorHandler_Abstract::$behavior protected property The name of the behavior plugin.
EntityReference_BehaviorHandler_Abstract::$plugin protected property The plugin definition.
EntityReference_BehaviorHandler_Abstract::access public function Determine if handler should appear. Overrides EntityReference_BehaviorHandler::access 1
EntityReference_BehaviorHandler_Abstract::delete public function Act before deleting an entity with an entity reference field. Overrides EntityReference_BehaviorHandler::delete 2
EntityReference_BehaviorHandler_Abstract::entityPostDelete public function Act after deleting an entity. Overrides EntityReference_BehaviorHandler::entityPostDelete
EntityReference_BehaviorHandler_Abstract::entityPostInsert public function Act after inserting an entity. Overrides EntityReference_BehaviorHandler::entityPostInsert 1
EntityReference_BehaviorHandler_Abstract::entityPostUpdate public function Act after updating an entity. Overrides EntityReference_BehaviorHandler::entityPostUpdate 1
EntityReference_BehaviorHandler_Abstract::insert public function Act before inserting an entity reference field. Overrides EntityReference_BehaviorHandler::insert 2
EntityReference_BehaviorHandler_Abstract::is_empty_alter public function Alter the empty status of a field item. Overrides EntityReference_BehaviorHandler::is_empty_alter
EntityReference_BehaviorHandler_Abstract::load public function Act on loading entity reference fields of entities. Overrides EntityReference_BehaviorHandler::load 2
EntityReference_BehaviorHandler_Abstract::postDelete public function Act after deleting an entity with an entity reference field. Overrides EntityReference_BehaviorHandler::postDelete
EntityReference_BehaviorHandler_Abstract::postInsert public function Act after inserting an entity reference field. Overrides EntityReference_BehaviorHandler::postInsert
EntityReference_BehaviorHandler_Abstract::postUpdate public function Act after updating an entity reference field. Overrides EntityReference_BehaviorHandler::postUpdate
EntityReference_BehaviorHandler_Abstract::presave public function Act on presaving an entity reference field. Overrides EntityReference_BehaviorHandler::presave
EntityReference_BehaviorHandler_Abstract::property_info_alter public function Alter the properties information of a field instance. Overrides EntityReference_BehaviorHandler::property_info_alter
EntityReference_BehaviorHandler_Abstract::schema_alter public function Alter the field schema. Overrides EntityReference_BehaviorHandler::schema_alter
EntityReference_BehaviorHandler_Abstract::update public function Act before updating an entity reference field. Overrides EntityReference_BehaviorHandler::update 2
EntityReference_BehaviorHandler_Abstract::validate public function Act on validating an entity reference field. Overrides EntityReference_BehaviorHandler::validate
EntityReference_BehaviorHandler_Abstract::views_data_alter public function Alter the views data of a field. Overrides EntityReference_BehaviorHandler::views_data_alter 1
EntityReference_BehaviorHandler_Abstract::__construct public function Constructor for the behavior. Overrides EntityReference_BehaviorHandler::__construct