本文整理汇总了PHP中Drupal\Component\Utility\NestedArray::getValue方法的典型用法代码示例。如果您正苦于以下问题:PHP NestedArray::getValue方法的具体用法?PHP NestedArray::getValue怎么用?PHP NestedArray::getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Component\Utility\NestedArray
的用法示例。
在下文中一共展示了NestedArray::getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: trigger
/**
* Button #submit callback: Triggers submission of element forms.
*
* @param array $form
* The form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
public static function trigger($form, FormStateInterface $form_state)
{
$triggered_element = $form_state->getTriggeringElement();
if (!empty($triggered_element['#ief_submit_trigger_all'])) {
// The parent form was submitted, process all IEFs and their children.
static::doSubmit($form, $form_state);
} else {
// A specific element was submitted, process it and all of its children.
$array_parents = $triggered_element['#array_parents'];
$array_parents = array_slice($array_parents, 0, -2);
$element = NestedArray::getValue($form, $array_parents);
static::doSubmit($element, $form_state);
}
}
示例2: ajaxSample
/**
* Ajax callback to render a sample of the input date format.
*
* @param array $form
* Form API array structure.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state information.
*
* @return AjaxResponse
* Ajax response with the rendered sample date using the given format. If
* the given format cannot be identified or was empty, the response will
* be empty as well.
*/
public static function ajaxSample(array $form, FormStateInterface $form_state)
{
$response = new AjaxResponse();
$format_value = NestedArray::getValue($form_state->getValues(), $form_state->getTriggeringElement()['#array_parents']);
if (!empty($format_value)) {
// Format the date with a custom date format with the given pattern.
// The object is not instantiated in an Ajax context, so $this->t()
// cannot be used here.
$format = t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $format_value)));
// Return a command instead of a string, since the Ajax framework
// automatically prepends an additional empty DIV element for a string,
// which breaks the layout.
$response->addCommand(new ReplaceCommand('#edit-date-format-suffix', '<small id="edit-date-format-suffix">' . $format . '</small>'));
}
return $response;
}
示例3: fieldSettingsFormValidate
/**
* Implements #element_validate callback for self::fieldSettingsForm().
*/
public static function fieldSettingsFormValidate(array $element, FormStateInterface $form_state)
{
$add_more_button_form_parents = array_merge($element['#array_parents'], ['line_items', 'add_more', 'add']);
// Only set the field settings as a value when it is not the "Add more"
// button that has been clicked.
$triggering_element = $form_state->getTriggeringElement();
if ($triggering_element['#array_parents'] != $add_more_button_form_parents) {
$values = $form_state->getValues();
$values = NestedArray::getValue($values, $element['#array_parents']);
$line_items_data = [];
foreach (PaymentLineItemsInput::getLineItems($element['line_items'], $form_state) as $line_item) {
$line_items_data[] = ['plugin_id' => $line_item->getPluginId(), 'plugin_configuration' => $line_item->getConfiguration()];
}
$value = ['currency_code' => $values['currency_code'], 'line_items_data' => $line_items_data];
$form_state->setValueForElement($element, $value);
}
}
示例4: ajaxRemove
/**
* Ajax callback to remove a field collection from a multi-valued field.
*
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AjaxResponse object.
*/
function ajaxRemove(array $form, FormStateInterface &$form_state)
{
// Process user input. $form and $form_state are modified in the process.
//\Drupal::formBuilder()->processForm($form['#form_id'], $form, $form_state);
// Retrieve the element to be rendered.
$trigger = $form_state->getTriggeringElement();
$form_parents = explode('/', $trigger['#ajax']['options']['query']['element_parents']);
$address = array_slice($form_parents, 0, -1);
$form = NestedArray::getValue($form, $address);
$status_messages = array('#theme' => 'status_messages');
$renderer = \Drupal::service('renderer');
$form['#prefix'] = empty($form['#prefix']) ? $renderer->render($status_messages) : $form['#prefix'] . $renderer->render($status_messages);
$output = $renderer->render($form);
drupal_process_attached($form);
// TODO: Preserve javascript. See https://www.drupal.org/node/2502743 .
$response = new AjaxResponse();
return $response->addCommand(new ReplaceCommand(NULL, $output));
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL)
{
// Add AJAX support.
$form['#prefix'] = '<div id="video-embed-dialog-form">';
$form['#suffix'] = '</div>';
// Ensure relevant dialog libraries are attached.
$form['#attached']['library'][] = 'editor/drupal.editor.dialog';
// Simple URL field and submit button for video URL.
$form['video_url'] = ['#type' => 'textfield', '#title' => $this->t('Video URL'), '#required' => TRUE, '#default_value' => $this->getUserInput($form_state, 'video_url')];
// If no settings are found, use the defaults configured in the filter
// formats interface.
$settings = $this->getUserInput($form_state, 'settings');
if (empty($settings) && ($editor = Editor::load($filter_format->id()))) {
$editor_settings = $editor->getSettings();
$plugin_settings = NestedArray::getValue($editor_settings, ['plugins', 'video_embed', 'defaults', 'children']);
$settings = $plugin_settings ? $plugin_settings : [];
}
// Create a settings form from the existing video formatter.
$form['settings'] = Video::mockInstance($settings)->settingsForm([], new FormState());
$form['settings']['#type'] = 'fieldset';
$form['settings']['#title'] = $this->t('Settings');
$form['actions'] = ['#type' => 'actions'];
$form['actions']['save_modal'] = ['#type' => 'submit', '#value' => $this->t('Save'), '#submit' => [], '#ajax' => ['callback' => '::ajaxSubmit', 'event' => 'click', 'wrapper' => 'video-embed-dialog-form']];
return $form;
}
示例6: validateForm
public function validateForm(array &$element, array &$form_state, \Payment $payment)
{
$values = \Drupal\Component\Utility\NestedArray::getValue($form_state['values'], $element['#parents']);
if (!empty($values['send_transfer_form'])) {
$payment->method_data['send_transfer_form'] = $values['send_transfer_form'];
}
}
示例7: transform
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
{
$new_value = $value;
if (is_array($value)) {
if (!$value) {
throw new MigrateException('Can not lookup without a value.');
}
} else {
$new_value = array($value);
}
$new_value = NestedArray::getValue($this->configuration['map'], $new_value, $key_exists);
if (!$key_exists) {
if (array_key_exists('default_value', $this->configuration)) {
if (!empty($this->configuration['bypass'])) {
throw new MigrateException('Setting both default_value and bypass is invalid.');
}
return $this->configuration['default_value'];
}
if (empty($this->configuration['bypass'])) {
throw new MigrateSkipRowException();
} else {
return $value;
}
}
return $new_value;
}
示例8: settingsForm
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor)
{
$editor_settings = $editor->getSettings();
$plugin_settings = NestedArray::getValue($editor_settings, ['plugins', 'video_embed', 'defaults', 'children']);
$settings = $plugin_settings ?: [];
$form['defaults'] = ['#title' => $this->t('Default Settings'), '#type' => 'fieldset', '#tree' => TRUE, 'children' => Video::mockInstance($settings)->settingsForm([], new FormState())];
return $form;
}
示例9: validateForm
public function validateForm(array &$element, array &$form_state, \Payment $payment)
{
$values = \Drupal\Component\Utility\NestedArray::getValue($form_state['values'], $element['#parents']);
$this->validateValues($element, $values);
// Merge in validated fields.
foreach (array('issuer', 'credit_card_number', 'secure_code', 'expiry_date') as $key) {
$payment->method_data[$key] = $values[$key];
}
}
示例10: onMigrateImport
/**
* Listener for migration imports.
*/
public function onMigrateImport(MigrateImportEvent $event)
{
$migration = $event->getMigration();
$configuration = $migration->getDestinationConfiguration();
$entity_types = NestedArray::getValue($configuration, ['content_translation_update_definitions']);
if ($entity_types) {
$entity_types = array_intersect_key($this->entityManager->getDefinitions(), array_flip($entity_types));
$this->updateDefinitions($entity_types);
}
}
示例11: massageFormValues
/**
* {@inheritdoc}
*/
public function massageFormValues(array $values, array $form, FormStateInterface $form_state)
{
$massaged_values = [];
foreach ($values as $delta => $item_values) {
$element = NestedArray::getValue($form, array_slice($item_values['array_parents'], count($form['#array_parents'])));
$plugin_selector = static::getPluginSelector($form_state, $element);
$plugin_selector->submitSelectorForm($element['plugin_selector'], $form_state);
$massaged_values[$delta] = ['plugin_instance' => $plugin_selector->getSelectedPlugin()];
}
return $massaged_values;
}
示例12: transform
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
{
if (!is_array($value)) {
throw new MigrateException('Input should be an array.');
}
$new_value = NestedArray::getValue($value, $this->configuration['index'], $key_exists);
if (!$key_exists) {
throw new MigrateException('Array index missing, extraction failed.');
}
return $new_value;
}
示例13: upload
/**
* Processes AJAX file uploads and deletions.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AjaxResponse object.
*/
public function upload(Request $request)
{
$form_parents = explode('/', $request->query->get('element_parents'));
$form_build_id = $request->query->get('form_build_id');
$request_form_build_id = $request->request->get('form_build_id');
if (empty($request_form_build_id) || $form_build_id !== $request_form_build_id) {
// Invalid request.
drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size()))), 'error');
$response = new AjaxResponse();
$status_messages = array('#theme' => 'status_messages');
return $response->addCommand(new ReplaceCommand(NULL, drupal_render($status_messages)));
}
try {
/** @var $ajaxForm \Drupal\system\FileAjaxForm */
$ajaxForm = $this->getForm($request);
$form = $ajaxForm->getForm();
$form_state = $ajaxForm->getFormState();
$commands = $ajaxForm->getCommands();
} catch (HttpExceptionInterface $e) {
// Invalid form_build_id.
drupal_set_message(t('An unrecoverable error occurred. Use of this form has expired. Try reloading the page and submitting again.'), 'error');
$response = new AjaxResponse();
$status_messages = array('#theme' => 'status_messages');
return $response->addCommand(new ReplaceCommand(NULL, drupal_render($status_messages)));
}
// Get the current element and count the number of files.
$current_element = NestedArray::getValue($form, $form_parents);
$current_file_count = isset($current_element['#file_upload_delta']) ? $current_element['#file_upload_delta'] : 0;
// Process user input. $form and $form_state are modified in the process.
drupal_process_form($form['#form_id'], $form, $form_state);
// Retrieve the element to be rendered.
$form = NestedArray::getValue($form, $form_parents);
// Add the special Ajax class if a new file was added.
if (isset($form['#file_upload_delta']) && $current_file_count < $form['#file_upload_delta']) {
$form[$current_file_count]['#attributes']['class'][] = 'ajax-new-content';
} else {
$form['#suffix'] .= '<span class="ajax-new-content"></span>';
}
$status_messages = array('#theme' => 'status_messages');
$form['#prefix'] .= drupal_render($status_messages);
$output = drupal_render($form);
drupal_process_attached($form);
$js = _drupal_add_js();
$settings = drupal_merge_js_settings($js['settings']['data']);
$response = new AjaxResponse();
foreach ($commands as $command) {
$response->addCommand($command, TRUE);
}
return $response->addCommand(new ReplaceCommand(NULL, $output, $settings));
}
示例14: process
/**
* Global #process callback for form elements.
*
* @param array $element
* The element render array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param array $complete_form
* The complete form structure.
*
* @return array
* The altered element array.
*
* @see \Drupal\bootstrap\Plugin\Alter\ElementInfo::alter
*/
public static function process(array $element, FormStateInterface $form_state, array &$complete_form)
{
if (!empty($element['#bootstrap_ignore_process'])) {
return $element;
}
static $theme;
if (!isset($theme)) {
$theme = Bootstrap::getTheme();
}
$e = Element::create($element, $form_state);
// Add "form-inline" class.
if ($e->hasClass('container-inline')) {
$e->replaceClass('container-inline', 'form-inline');
}
if ($e->isType(['color', 'date', 'number', 'password', 'password_confirm', 'range', 'tel', 'weight'])) {
$e->addClass('form-inline', 'wrapper_attributes');
}
// Add "form-group" class, don't replace "form-wrapper" as that is needed
// by some JavaScript for certain functionality to work.
if ($e->hasClass('form-wrapper')) {
$e->addClass('form-group');
}
// Check for errors and set the "has_error" property flag.
$errors = $e->getError();
$e->setProperty('errors', $errors);
if (isset($errors) || $e->getProperty('required') && $theme->getSetting('forms_required_has_error')) {
$e->setProperty('has_error', TRUE);
}
// Automatically inject the nearest button found after this element if
// #input_group_button exists.
if ($e->getProperty('input_group_button')) {
// Obtain the parent array to limit search.
$array_parents = $e->getProperty('array_parents', []);
// Remove the current element from the array.
array_pop($array_parents);
// If element is nested, return the referenced parent from the form.
// Otherwise return the complete form.
$parent = Element::create($array_parents ? NestedArray::getValue($complete_form, $array_parents) : $complete_form, $form_state);
// Find the closest button.
if ($button = self::findButton($parent)) {
$e->setProperty('field_suffix', $button->setIcon()->getArray());
$button->setProperty('access', FALSE);
}
}
return $element;
}
示例15: getVariablesData
/**
* Get all system variables
*
* @return array()
*/
public function getVariablesData()
{
$data = array();
$variables = array('acquia_spi_send_node_user', 'acquia_spi_admin_priv', 'acquia_spi_module_diff_data', 'acquia_spi_send_watchdog', 'acquia_spi_use_cron', 'cache_backends', 'cache_default_class', 'cache_inc', 'cron_safe_threshold', 'googleanalytics_cache', 'error_level', 'preprocess_js', 'page_cache_maximum_age', 'block_cache', 'preprocess_css', 'page_compression', 'cache', 'cache_lifetime', 'cron_last', 'clean_url', 'redirect_global_clean', 'theme_zen_settings', 'site_offline', 'site_name', 'user_register', 'user_signatures', 'user_admin_role', 'user_email_verification', 'user_cancel_method', 'filter_fallback_format', 'dblog_row_limit', 'date_default_timezone', 'file_default_scheme', 'install_profile', 'maintenance_mode', 'update_last_check', 'site_default_country', 'acquia_spi_saved_variables', 'acquia_spi_set_variables_automatic', 'acquia_spi_ignored_set_variables', 'acquia_spi_set_variables_override');
$allConfigData = self::getAllConfigs();
$spi_def_vars = \Drupal::config('acquia_connector.settings')->get('spi.def_vars');
$waived_spi_def_vars = \Drupal::config('acquia_connector.settings')->get('spi.def_waived_vars');
// Merge hard coded $variables with vars from SPI definition.
foreach ($spi_def_vars as $var_name => $var) {
if (!in_array($var_name, $waived_spi_def_vars) && !in_array($var_name, $variables)) {
$variables[] = $var_name;
}
}
// @todo Add comment settings for node types.
foreach ($variables as $name) {
if (!empty($this->mapping[$name])) {
// state
if ($this->mapping[$name][0] == 'state' and !empty($this->mapping[$name][1])) {
$data[$name] = \Drupal::state()->get($this->mapping[$name][1]);
} elseif ($this->mapping[$name][0] == 'settings' and !empty($this->mapping[$name][1])) {
$data[$name] = Settings::get($this->mapping[$name][1]);
} else {
$key_exists = NULL;
$value = Utility\NestedArray::getValue($allConfigData, $this->mapping[$name], $key_exists);
if ($key_exists) {
$data[$name] = $value;
} else {
$data[$name] = 0;
}
}
} else {
// @todo: Implement D8 way to update variables mapping.
$data[$name] = 'Variable not implemented.';
}
}
// Unset waived vars so they won't be sent to NSPI.
foreach ($data as $var_name => $var) {
if (in_array($var_name, $waived_spi_def_vars)) {
unset($data[$var_name]);
}
}
// Collapse to JSON string to simplify transport.
return Json::encode($data);
}