You are here

function _entityreference_get_behavior_elements in Entity reference 7

Get the field or instance elements for the field configuration.

2 calls to _entityreference_get_behavior_elements()
_entityreference_field_instance_settings_form in ./entityreference.module
Implements hook_field_settings_form().
_entityreference_field_settings_process in ./entityreference.module
Callback for custom element processing.

File

./entityreference.module, line 624
Entityreference primary module file.

Code

function _entityreference_get_behavior_elements(&$element, $field, $instance, $level) {

  // Add the accessible behavior handlers.
  $behavior_plugins = entityreference_get_accessible_behavior_plugins($field, $instance);
  if ($behavior_plugins[$level]) {
    $element['behaviors'] = array();
    foreach ($behavior_plugins[$level] as $name => $plugin) {
      if ($level == 'field') {
        $settings = !empty($field['settings']['handler_settings']['behaviors'][$name]) ? $field['settings']['handler_settings']['behaviors'][$name] : array();
      }
      else {
        $settings = !empty($instance['settings']['behaviors'][$name]) ? $instance['settings']['behaviors'][$name] : array();
      }
      $settings += array(
        'status' => $plugin['force enabled'],
      );

      // Render the checkbox.
      $element['behaviors'][$name] = array(
        '#tree' => TRUE,
      );
      $element['behaviors'][$name]['status'] = array(
        '#type' => 'checkbox',
        '#title' => check_plain($plugin['title']),
        '#description' => $plugin['description'],
        '#default_value' => $settings['status'],
        '#disabled' => $plugin['force enabled'],
        '#ajax' => TRUE,
      );
      if ($settings['status']) {
        $handler = _entityreference_get_behavior_handler($name);
        if ($behavior_elements = $handler
          ->settingsForm($field, $instance)) {
          foreach ($behavior_elements as $key => &$behavior_element) {
            $behavior_element += array(
              '#default_value' => !empty($settings[$key]) ? $settings[$key] : NULL,
            );
          }

          // Get the behavior settings.
          $behavior_elements += array(
            '#type' => 'container',
            '#process' => array(
              '_entityreference_form_process_merge_parent',
            ),
            '#attributes' => array(
              'class' => array(
                'entityreference-settings',
              ),
            ),
          );
          $element['behaviors'][$name]['settings'] = $behavior_elements;
        }
      }
    }
  }
}