diff --git a/select_or_other.api.php b/select_or_other.api.php index 83681c6..825a83d 100644 --- a/select_or_other.api.php +++ b/select_or_other.api.php @@ -5,8 +5,9 @@ * API documentation for Select or other. */ - /** + * Implements hook_select_or_other_available_options(). + * * Provide a list of options for a select or other field. Options can be keyed, * unkeyed or a combination of both. Keyed values should be entered in a * key|value fashion. Unkeyed options will automatically be keyed with a key @@ -15,7 +16,7 @@ * Options provided using this hook can be overwritten by options provided in * the 'Available options' field on the instance settings form. */ -function hook_select_or_other_available_options($entity_type, $bundle, $field_name){ +function hook_select_or_other_available_options($entity_type, $bundle, $field_name) { if ($entity_type === 'node' && $bundle === 'page' && $field_name === 'field_some_field') { return array( 'keyed|A keyed value', @@ -23,3 +24,17 @@ function hook_select_or_other_available_options($entity_type, $bundle, $field_na ); } } + +/** + * Implements hook_select_or_other_process_alter(). + * + * Provide a hook to alter the widget depending on the context and form_state. + * In this example we remove the attached files and remove the 'other' textfield + * depending on the state of the form submitted. + */ +function hook_select_or_other_process_alter(&$element, &$form_state, $context) { + unset($element['#attached']); + if ($form_state['submitted']) { + $element['other']['#access'] = FALSE; + } +} diff --git a/select_or_other.field_widget.inc b/select_or_other.field_widget.inc index 348bc17..ea65e46 100644 --- a/select_or_other.field_widget.inc +++ b/select_or_other.field_widget.inc @@ -370,7 +370,8 @@ function select_or_other_field_widget_settings_form($field, $instance) { function select_or_other_field_create_instance($instance) { if ( empty($instance['widget']['settings']['available_options']) && - empty($instance['widget']['settings']['available_options_php']) + empty($instance['widget']['settings']['available_options_php']) && + empty($instance['widget']['settings']['other']) ) { return; } diff --git a/select_or_other.module b/select_or_other.module index d439318..0babdc1 100644 --- a/select_or_other.module +++ b/select_or_other.module @@ -273,6 +273,8 @@ function select_or_other_element_process($element, &$form_state) { $element['other']['#size'] = $element['#other_size']; } + drupal_alter('select_or_other_process', $element, $form_state, $context); + return $element; }