You are here

public static function EntityReference_SelectionHandler_DDF::settingsForm in Dynamic dependent fields 7

Implements EntityReferenceHandler::settingsForm().

Overrides EntityReference_SelectionHandler_Views::settingsForm

File

modules/ddf_entityreference/plugins/selection/EntityReference_SelectionHandler_DDF.class.php, line 45

Class

EntityReference_SelectionHandler_DDF
Entity handler for Views.

Code

public static function settingsForm($field, $instance) {
  $form = parent::settingsForm($field, $instance);
  if (isset($form['view']['args'])) {
    $master_fields = array();
    $all_instances = field_info_instances($instance['entity_type'], $instance['bundle']);
    foreach ($all_instances as $other_instance) {
      if ($other_instance['field_name'] == $instance['field_name']) {
        continue;
      }
      if ($other_instance['widget']['type'] != 'options_select' && $other_instance['widget']['type'] != 'options_buttons') {
        continue;
      }
      $other_field = field_info_field($other_instance['field_name']);
      if ($other_field['cardinality'] != 1) {
        continue;
      }
      if ($other_field['type'] === 'entityreference' || count($other_field['columns']) === 1) {
        $master_fields[$other_instance['field_name']] = htmlspecialchars($other_instance['label']);
      }
    }
    drupal_alter('ddf_entityreference_master_fields', $master_fields, $instance, $all_instances);
    if (!empty($master_fields)) {
      $dynamic_token_list = '';
      foreach ($master_fields as $master_field_name => $master_field_label) {
        $dynamic_token_list .= '<strong>{' . $master_field_name . '}</strong> - ' . $master_field_label . '<br />';
      }
      $form['view']['dynamic_help'] = array(
        '#type' => 'item',
        '#title' => t('Dynamic arguments'),
        '#description' => t('The list of entities that can be referenced can depend on the current values of other fields. When the user changes these fields, the list is rebuilt.'),
        '#markup' => t('The following dynamic tokens can be used as view arguments:') . '<br />' . $dynamic_token_list,
      );
    }
  }
  return $form;
}