/** * Creates a date field from an array of settings values. * * All values have defaults, only need to specify values that need to be * different. */ protected function createDateField($values = array()) { extract($values); $field_name = !empty($field_name) ? $field_name : 'field_test'; $entity_type = !empty($entity_type) ? $entity_type : 'node'; $bundle = !empty($bundle) ? $bundle : 'story'; $label = !empty($label) ? $label : 'Test'; $field_type = !empty($field_type) ? $field_type : 'datetime'; $repeat = !empty($repeat) ? $repeat : 0; $todate = !empty($todate) ? $todate : 'optional'; $widget_type = !empty($widget_type) ? $widget_type : 'date_select'; $tz_handling = !empty($tz_handing) ? $tz_handling : 'site'; $granularity = !empty($granularity) ? $granularity : array('year', 'month', 'day', 'hour', 'minute'); $year_range = !empty($year_range) ? $year_range : '2010:+1'; $input_format = !empty($input_format) ? $input_format : variable_get('date_format_html_date', 'Y-m-d') . ' ' . variable_get('date_format_html_time', 'H:i:s'); $input_format_custom = !empty($input_format_custom) ? $input_format_custom : ''; $text_parts = !empty($text_parts) ? $text_parts : array(); $increment = !empty($increment) ? $increment : 15; $default_value = !empty($default_value) ? $default_value : 'now'; $default_value2 = !empty($default_value2) ? $default_value2 : 'blank'; $default_format = !empty($default_format) ? $default_format : 'long'; $cache_enabled = !empty($cache_enabled); $cache_count = !empty($cache_count) ? $cache_count : 4; $field = array('field_name' => $field_name, 'type' => $field_type, 'cardinality' => !empty($repeat) ? FIELD_CARDINALITY_UNLIMITED : 1, 'settings' => array('granularity' => $granularity, 'tz_handling' => $tz_handling, 'timezone_db' => date_get_timezone_db($tz_handling), 'repeat' => $repeat, 'todate' => $todate, 'cache_enabled' => $cache_enabled, 'cache_count' => $cache_count)); $instance = array('entity_type' => $entity_type, 'field_name' => $field_name, 'label' => $label, 'bundle' => $bundle, 'weight' => -4, 'widget' => array('type' => $widget_type, 'settings' => array('increment' => $increment, 'year_range' => $year_range, 'input_format' => $input_format, 'input_format_custom' => $input_format_custom, 'text_parts' => $text_parts, 'label_position' => 'above'), 'weight' => -4), 'settings' => array('default_value' => $default_value, 'default_value2' => $default_value2)); $instance['display'] = array('default' => array('label' => 'above', 'type' => 'date_default', 'settings' => array('format_type' => $default_format, 'show_repeat_rule' => 'show', 'multiple_number' => '', 'multiple_from' => '', 'multiple_to' => '', 'fromto' => 'both'), 'module' => 'date', 'weight' => 0), 'teaser' => array('label' => 'above', 'type' => 'date_default', 'weight' => 0, 'settings' => array('format_type' => $default_format, 'show_repeat_rule' => 'show', 'multiple_number' => '', 'multiple_from' => '', 'multiple_to' => '', 'fromto' => 'both'), 'module' => 'date')); $field = field_create_field($field); $instance = field_create_instance($instance); field_info_cache_clear(TRUE); field_cache_clear(TRUE); // Look at how the field got configured. $this->drupalGet("admin/structure/types/manage/{$bundle}/fields/{$field_name}"); $this->drupalGet("admin/structure/types/manage/{$bundle}/display"); }
/** * Save the picture mapping. * * @return * If the record insert or update failed, returns FALSE. If it succeeded, * returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed. */ public function save() { $update = array(); $this->cleanMappings(); $data = $this->toArray(); if (isset($this->id) && $this->id) { $update = array('id'); $data['id'] = $this->id; } $return = drupal_write_record('picture_mapping', $data, $update); module_load_include('info.inc', 'field'); field_info_cache_clear(); $this->setValues(ctools_export_get_schema('picture_mapping'), $data); $this->loadBreakpointGroup(); return $return; }
/** * Allow modules to react to language settings changes. * * Every module needing to act when the number of enabled languages changes * should implement this. This is an "internal" hook and should not be invoked * elsewhere. The typical implementation would trigger some kind of rebuilding, * this way system components could properly react to the change of the enabled * languages number. */ function hook_multilingual_settings_changed() { field_info_cache_clear(); }
public static function purgeField(array $field) { $field = static::readFieldById($field['id']); if (empty($field['deleted'])) { throw new FieldException("Field not yet marked as deleted."); } if (!module_exists($field['storage']['module'])) { throw new FieldException("The {$field['storage']['module']} module needs to be enabled in order to delete field ID {$field['id']}."); } $instances = field_read_instances(array('field_id' => $field['id']), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); if (count($instances) > 0) { throw new FieldException(t('Attempt to purge a field @field_name that still has instances.', array('@field_name' => $field['field_name']))); } db_delete('field_config')->condition('id', $field['id'])->execute(); // Notify the storage engine. module_invoke($field['storage']['module'], 'field_storage_purge_field', $field); // Clear the cache. field_info_cache_clear(); // Invoke external hooks after the cache is cleared for API consistency. module_invoke_all('field_purge_field', $field); watchdog('helper', "Field ID {$field['id']} completely removed."); }
/** * Called to save the final product from the edit form. */ function edit_save_form($form_state) { parent::edit_save_form($form_state); // Entity bundle has been saved. $op = $form_state['form type'] == 'add' ? 'insert' : 'update'; field_attach_insert('heartbeat_activity', $form_state['item']); module_invoke_all("entity_{$op}", $form_state['item'], 'heartbeat_activity'); field_info_cache_clear(); }
/** * Implements Drupal\configuration\Config\Configuration::saveToActiveStore(). */ public function saveToActiveStore(ConfigIteratorSettings &$settings) { field_info_cache_clear(); // Load all the existing fields and instance up-front so that we don't // have to rebuild the cache all the time. $existing_fields = field_info_fields(); $existing_instances = field_info_instances(); $field = $this->getData(); // Create or update field. $field_config = $field['field_config']; if (isset($existing_fields[$field_config['field_name']])) { $existing_field = $existing_fields[$field_config['field_name']]; if ($field_config + $existing_field != $existing_field) { field_update_field($field_config); } } else { field_create_field($field_config); $existing_fields[$field_config['field_name']] = $field_config; } // Create or update field instance. $field_instance = $field['field_instance']; if (isset($existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']])) { $existing_instance = $existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']]; if ($field_instance + $existing_instance != $existing_instance) { field_update_instance($field_instance); } } else { field_create_instance($field_instance); $existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']] = $field_instance; } variable_set('menu_rebuild_needed', TRUE); $settings->addInfo('imported', $this->getUniqueId()); }