You are here

function entity_background_field_widget_form_alter in Entity background 7

Implements hook_field_widget_form_alter().

File

./entity_background.module, line 387
Module file entity background.

Code

function entity_background_field_widget_form_alter(&$element, &$form_state, $context) {
  if (!empty($element['#field_name']) && $element['#field_name'] == EB_FIELD) {
    $form = $context['form'];
    $parent_para = $form['#field_name'];
    $parent_delta = $form['#delta'];
    $language = $form['#language'];
    $groups = $element['#groups'];
    $input_name = $parent_para . '[' . $language . '][' . $parent_delta . '][' . EB_FIELD . '][' . $language . '][0][' . EB_SELECTION_FIELD . '][' . $language . ']';
    foreach ($groups as $key => $group) {

      // Child field items.
      $fields = $group->children;
      $plugin = entity_background_get_plugin_from_group_name($key);
      foreach ($fields as $field) {
        $element[$field]['#states'] = array(
          'visible' => array(
            ':input[name="' . $input_name . '"]' => array(
              'value' => EB_FG_PREFIX . $plugin,
            ),
          ),
        );
      }
    }
  }
}