You are here

function title_field_attach_form in Title 7

Implements hook_field_attach_form().

Hide legacy field widgets on the assumption that this is always called on fieldable entity forms.

File

./title.module, line 594

Code

function title_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
  list(, , $bundle) = entity_extract_ids($entity_type, $entity);
  $fr_info = title_field_replacement_info($entity_type);
  if (!empty($fr_info)) {
    foreach ($fr_info as $legacy_field => $info) {
      if (isset($form[$legacy_field]) && title_field_replacement_enabled($entity_type, $bundle, $legacy_field)) {

        // Inherit the access from the title widget, so that other modules
        // restricting access to it keep working.
        $replaced = isset($form[$legacy_field]['#field_replacement']) ? $form[$legacy_field]['#field_replacement'] : FALSE;
        if (!$replaced && isset($form[$legacy_field]['#access'])) {
          $form[$info['field']['field_name']]['#access'] = $form[$legacy_field]['#access'];
        }

        // Add class from legacy field so behaviors can still be applied on
        // title widget.
        $form[$info['field']['field_name']]['#attributes']['class'] = array(
          'form-item-' . $legacy_field,
        );

        // Restrict access to the legacy field form element and mark it as
        // replaced.
        $form[$legacy_field]['#access'] = FALSE;
        $form[$legacy_field]['#field_replacement'] = TRUE;
      }
    }
  }
}