本文整理汇总了PHP中form_set_value函数的典型用法代码示例。如果您正苦于以下问题:PHP form_set_value函数的具体用法?PHP form_set_value怎么用?PHP form_set_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了form_set_value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: elementValidate
/**
* {@inheritdoc}
*/
public function elementValidate($element, FormStateInterface $form_state, $form)
{
$auto_create = $this->getSelectionHandlerSetting('auto_create');
// If a value was entered into the autocomplete.
$value = NULL;
if (!empty($element['#value'])) {
// Take "label (entity id)', match the id from parenthesis.
// @todo: Lookup the entity type's ID data type and use it here.
// https://drupal.org/node/2107249
if ($this->isContentReferenced() && preg_match("/.+\\((\\d+)\\)/", $element['#value'], $matches)) {
$value = $matches[1];
} elseif (preg_match("/.+\\(([\\w.]+)\\)/", $element['#value'], $matches)) {
$value = $matches[1];
}
if ($value === NULL) {
// Try to get a match from the input string when the user didn't use the
// autocomplete but filled in a value manually.
$handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($this->fieldDefinition);
$value = $handler->validateAutocompleteInput($element['#value'], $element, $form_state, $form, !$auto_create);
}
if (!$value && $auto_create && count($this->getSelectionHandlerSetting('target_bundles')) == 1) {
// Auto-create item. See
// \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::presave().
$value = array('target_id' => NULL, 'entity' => $this->createNewEntity($element['#value'], $element['#autocreate_uid']), '_weight' => $element['#weight']);
// Change the element['#parents'], so in form_set_value() we
// populate the correct key.
array_pop($element['#parents']);
}
}
form_set_value($element, $value, $form_state);
}
示例2: validateName
/**
* Form element validation handler for 'name' in form_test_validate_form().
*/
public function validateName(&$element, FormStateInterface $form_state)
{
$triggered = FALSE;
if ($form_state->getValue('name') == 'element_validate') {
// Alter the form element.
$element['#value'] = '#value changed by #element_validate';
// Alter the submitted value in $form_state.
form_set_value($element, 'value changed by form_set_value() in #element_validate', $form_state);
$triggered = TRUE;
}
if ($form_state->getValue('name') == 'element_validate_access') {
$form_state->set('form_test_name', $form_state->getValue('name'));
// Alter the form element.
$element['#access'] = FALSE;
$triggered = TRUE;
} elseif ($form_state->has('form_test_name')) {
// To simplify this test, just take over the element's value into $form_state.
form_set_value($element, $form_state->get('form_test_name'), $form_state);
$triggered = TRUE;
}
if ($triggered) {
// Output the element's value from $form_state.
drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state->getValue('name'))));
// Trigger a form validation error to see our changes.
$form_state->setErrorByName('');
}
}
示例3: validateName
/**
* Form element validation handler for 'name' in form_test_validate_form().
*/
public function validateName(&$element, &$form_state)
{
$triggered = FALSE;
if ($form_state['values']['name'] == 'element_validate') {
// Alter the form element.
$element['#value'] = '#value changed by #element_validate';
// Alter the submitted value in $form_state.
form_set_value($element, 'value changed by form_set_value() in #element_validate', $form_state);
$triggered = TRUE;
}
if ($form_state['values']['name'] == 'element_validate_access') {
$form_state['storage']['form_test_name'] = $form_state['values']['name'];
// Alter the form element.
$element['#access'] = FALSE;
$triggered = TRUE;
} elseif (!empty($form_state['storage']['form_test_name'])) {
// To simplify this test, just take over the element's value into $form_state.
form_set_value($element, $form_state['storage']['form_test_name'], $form_state);
$triggered = TRUE;
}
if ($triggered) {
// Output the element's value from $form_state.
drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state['values']['name'])));
// Trigger a form validation error to see our changes.
form_set_error('', $form_state);
}
}
示例4: da_vinci_form_system_theme_settings_submit
/**
* Form submit for da_vinci_form_system_theme_settings_alter().
*/
function da_vinci_form_system_theme_settings_submit($form, &$form_state)
{
$exclude_css = array_filter(array_map('trim', explode("\n", $form_state['values']['css_exclude'])));
$exclude_js = array_filter(array_map('trim', explode("\n", $form_state['values']['js_exclude'])));
form_set_value(array('#parents' => array('css_exclude')), $exclude_css, $form_state);
form_set_value(array('#parents' => array('js_exclude')), $exclude_js, $form_state);
}
示例5: entityreference_prepopulate_providers_validate
/**
* Element validate; Set the value of the providers.
*/
function entityreference_prepopulate_providers_validate($element, &$form_state)
{
$value = $form_state['values']['instance']['settings']['behaviors']['prepopulate']['providers']['enabled'];
// Sort the value by the weight.
uasort($value, 'drupal_sort_weight');
form_set_value($element, $value, $form_state);
}
示例6: multipleValidate
/**
* Element validation helper.
*/
public static function multipleValidate($element, FormStateInterface $form_state)
{
$values = array_map('trim', explode(',', $element['#value']));
$items = array();
foreach ($values as $value) {
$items[] = array('value' => $value);
}
form_set_value($element, $items, $form_state);
}
示例7: drupalexp_form_system_theme_settings_validate
function drupalexp_form_system_theme_settings_validate(&$form, &$form_state)
{
$drupalexp_layouts = '';
$i = 0;
while (isset($form_state['input']['dexp_layout_' . $i])) {
$drupalexp_layouts .= $form_state['input']['dexp_layout_' . $i];
$i++;
}
form_set_value($form['layout_settings']['drupalexp_layouts'], $drupalexp_layouts, $form_state);
}
示例8: edit_form_validate
/**
* @todo
*/
function edit_form_validate(&$form, &$form_state)
{
parent::edit_form_validate($form, $form_state);
$values = $form_state['values'];
if ($values['parent'] == '_none') {
form_set_value(array('#parents' => array('parent')), '', $form_state);
} else {
form_set_value(array('#parents' => array('mode')), DELTA_PRESERVE, $form_state);
}
}
示例9: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state)
{
if ($form_state['values']['name'] == 'validate') {
// Alter the form element.
$form['name']['#value'] = '#value changed by #validate';
// Alter the submitted value in $form_state.
form_set_value($form['name'], 'value changed by form_set_value() in #validate', $form_state);
// Output the element's value from $form_state.
drupal_set_message(t('@label value: @value', array('@label' => $form['name']['#title'], '@value' => $form_state['values']['name'])));
// Trigger a form validation error to see our changes.
form_set_error('', $form_state);
}
}
示例10: alpha_theme_settings_validate_primary
/**
* Form element validation handler for validating the primary region setting for zones.
*/
function alpha_theme_settings_validate_primary(&$element, &$form_state)
{
if ($element['#value'] != '_none') {
$values = $form_state['values'];
if ($values['alpha_region_' . $element['#value'] . '_zone'] != $element['#zone']) {
form_set_value($element, NULL, $form_state);
} else {
$sum = 0;
foreach ($form_state['regions'] as $region => $item) {
if ($values['alpha_region_' . $region . '_zone'] == $element['#zone']) {
$sum += $values['alpha_region_' . $region . '_columns'];
$sum += $values['alpha_region_' . $region . '_prefix'];
$sum += $values['alpha_region_' . $region . '_suffix'];
}
}
if ($sum > $values['alpha_zone_' . $element['#zone'] . '_columns']) {
form_error($element, t('You have specified the %region region as the primary region for the %zone zone but the summed region width is greater than the number of available columns for that zone.', array('%region' => $form_state['regions'][$element['#value']]['name'], '%zone' => $form_state['zones'][$element['#zone']]['name'])));
}
}
}
}
示例11: elementValidate
/**
* {@inheritdoc}
*/
public function elementValidate($element, &$form_state, $form)
{
$value = array();
// If a value was entered into the autocomplete.
$handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($this->fieldDefinition);
$bundles = entity_get_bundles($this->getFieldSetting('target_type'));
$auto_create = $this->getSelectionHandlerSetting('auto_create');
if (!empty($element['#value'])) {
$value = array();
foreach (Tags::explode($element['#value']) as $input) {
$match = FALSE;
// Take "label (entity id)', match the ID from parenthesis when it's a
// number.
if (preg_match("/.+\\((\\d+)\\)/", $input, $matches)) {
$match = $matches[1];
} elseif (preg_match("/.+\\(([\\w.]+)\\)/", $input, $matches)) {
$match = $matches[1];
} else {
// Try to get a match from the input string when the user didn't use
// the autocomplete but filled in a value manually.
$match = $handler->validateAutocompleteInput($input, $element, $form_state, $form, !$auto_create);
}
if ($match) {
$value[] = array('target_id' => $match);
} elseif ($auto_create && (count($this->getSelectionHandlerSetting('target_bundles')) == 1 || count($bundles) == 1)) {
// Auto-create item. See
// \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::presave().
$value[] = array('target_id' => NULL, 'entity' => $this->createNewEntity($input, $element['#autocreate_uid']));
}
}
}
// Change the element['#parents'], so in form_set_value() we
// populate the correct key.
array_pop($element['#parents']);
form_set_value($element, $value, $form_state);
}
示例12: validateElement
/**
* Form validation handler for widget elements.
*
* @param array $element
* The form element.
* @param array $form_state
* The form state.
*/
public static function validateElement(array $element, array &$form_state)
{
if ($element['#required'] && $element['#value'] == '_none') {
\Drupal::formBuilder()->setError($element, $form_state, t('!name field is required.', array('!name' => $element['#title'])));
}
// Massage submitted form values.
// Drupal\Core\Field\WidgetBase::submit() expects values as
// an array of values keyed by delta first, then by column, while our
// widgets return the opposite.
if (is_array($element['#value'])) {
$values = array_values($element['#value']);
} else {
$values = array($element['#value']);
}
// Filter out the 'none' option. Use a strict comparison, because
// 0 == 'any string'.
$index = array_search('_none', $values, TRUE);
if ($index !== FALSE) {
unset($values[$index]);
}
// Transpose selections from field => delta to delta => field.
$items = array();
foreach ($values as $value) {
$items[] = array($element['#key_column'] => $value);
}
form_set_value($element, $items, $form_state);
}
示例13: devis_user_profile_form_validate
function devis_user_profile_form_validate($form, &$form_state)
{
// This is a check in case the javascript is disabled for whatever reason.
if (isset($form['profile_budget_profile']['field_active_regions_belgium'])) {
$belgium = FALSE;
$count = 0;
// Check if Belgium is selected among the choices.
$lang = $form['profile_budget_profile']['field_active_regions_belgium']['#language'];
foreach ($form_state['values']['profile_budget_profile']['field_active_regions_belgium'][$lang] as $k => $val) {
$count++;
if ($val['value'] == 'BEL') {
$belgium = TRUE;
}
}
// If Belgium is selected, then asign only Belgium as the value.
if ($belgium && $count > 1) {
$new_value = array($lang => array(0 => array('value' => 'BEL')));
$value['#parents'] = array('profile_budget_profile', 'field_active_regions_belgium');
form_set_value($value, $new_value, $form_state);
}
}
if (isset($form_state['values']['mail'])) {
// E-mail check for duplicate user.
$user_check = user_load_by_mail($form_state['values']['mail']);
if ($user_check && $form['#user']->uid != $user_check->uid) {
$site_name = variable_get('site_name', '3devis.be');
form_set_error('mail', t('The specified email is already registered in !site_name.', array('!site_name' => $site_name)));
}
// E-mail check.
if (!valid_email_address($form_state['values']['mail'])) {
form_set_error('mail', t('The specified email is not a valid email.'));
}
}
devis_field_phone_belgium_validate($form, $form_state);
devis_field_tva_validate($form, $form_state);
}
示例14: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
form_set_value($form['id'], $this->targetEntityTypeId . '.' . $form_state['values']['id'], $form_state);
}
示例15: _agency_1_theme_settings_map
function _agency_1_theme_settings_map($form, &$form_state)
{
$validators = array('file_validate_is_image' => array());
$file = file_save_upload('background_file', $validators);
$map_file = file_save_upload('footer_contact_us_map_image', $validators);
//Map image
if (isset($map_file)) {
// File upload was attempted.
if ($map_file) {
// Move the file, into the Drupal file system
if ($map_filename = file_unmanaged_copy($map_file->uri, 'public://background_images', FILE_EXISTS_RENAME)) {
//resize, if necessary
$map_resized = image_load($map_file->uri);
list($map_width, $map_height) = getimagesize($map_file->uri);
if ($map_width > 150 || $map_height > 150) {
if ($map_width / $map_height >= 1) {
image_scale($map_resized, 150);
} else {
image_scale($map_resized, null, 150);
}
image_save($map_resized, $map_filename, FILE_EXISTS_RENAME);
$map_resized->status = FILE_STATUS_PERMANENT;
drupal_set_message('Uploaded image was greater than 150px. Image has been resized.');
}
//end resize
unset($form['footer_contact_us']['settings']['footer_contact_us_map_path']);
$form['footer_contact_us']['settings']['footer_contact_us_map_path']['#value'] = $map_filename;
$form['footer_contact_us_map_path']['#parents'] = array('footer_contact_us_map_path');
form_set_value($form['footer_contact_us_map_path'], file_create_url($map_filename), $form_state);
watchdog('Theme Settings', 'New Footer Map Image uploaded: ' . file_create_url($map_filename));
drupal_set_message('Map Image uploaded. URL: ' . file_create_url($map_filename));
} else {
form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
}
} else {
// File upload failed.
form_set_error('background_file', t('The image could not be uploaded.'));
}
}
}