Commit df7ced55 authored by alexpott's avatar alexpott

Issue #2561259 by stefan.r, lauriii, joelpittet, andypost: Cast (optgroup)...

Issue #2561259 by stefan.r, lauriii, joelpittet, andypost: Cast (optgroup) array keys that may hold translated strings to string
parent e38ae991
......@@ -945,7 +945,10 @@ public function getEntityTypeLabels($group = FALSE) {
foreach ($definitions as $entity_type_id => $definition) {
if ($group) {
$options[$definition->getGroupLabel()][$entity_type_id] = $definition->getLabel();
// We cast the optgroup label to string as array keys must not be
// objects and t() may return a TranslationWrapper once issue #2557113
// lands.
$options[(string) $definition->getGroupLabel()][$entity_type_id] = $definition->getLabel();
}
else {
$options[$entity_type_id] = $definition->getLabel();
......@@ -960,7 +963,9 @@ public function getEntityTypeLabels($group = FALSE) {
// Make sure that the 'Content' group is situated at the top.
$content = $this->t('Content', array(), array('context' => 'Entity type group'));
$options = array($content => $options[$content]) + $options;
// We cast the optgroup label to string as array keys must not be objects
// and t() may return a TranslationWrapper once issue #2557113 lands.
$options = array((string) $content => $options[(string) $content]) + $options;
}
return $options;
......
......@@ -18,6 +18,10 @@
* An associative array containing:
* - editor: An editor object.
* - plugins: A list of plugins.
* - active_buttons: A list of disabled buttons.
* - disabled_buttons: A list of disabled buttons.
* - multiple_buttons: A list of multiple buttons that may be added multiple
* times.
*/
function template_preprocess_ckeditor_settings_toolbar(&$variables) {
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
......@@ -113,6 +117,9 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) {
$variables['active_buttons'] = array();
foreach ($active_buttons as $row_number => $button_row) {
foreach ($button_groups[$row_number] as $group_name) {
// We cast the group name to string as array keys must not be objects
// and t() may return a TranslationWrapper once issue #2557113 lands.
$group_name = (string) $group_name;
$variables['active_buttons'][$row_number][$group_name] = array(
'group_name_class' => Html::getClass($group_name),
'buttons' => array(),
......
......@@ -299,8 +299,11 @@ function comment_form_field_ui_field_storage_add_form_alter(&$form, FormStateInt
$form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($route_match->getParameter('commented_entity_type'), $route_match->getParameter('field_name'));
}
if (!_comment_entity_uses_integer_id($form_state->get('entity_type_id'))) {
// We cast the optgroup label to string as array keys must not be objects
// and t() will return a TranslationWrapper once issue #2557113 lands.
$optgroup = (string) t('General');
// You cannot use comment fields on entity types with non-integer IDs.
unset($form['add']['new_storage_type']['#options'][t('General')]['comment']);
unset($form['add']['new_storage_type']['#options'][$optgroup]['comment']);
}
}
......
......@@ -126,10 +126,13 @@ function entity_reference_field_config_presave(FieldConfigInterface $field) {
* Implements hook_form_FORM_ID_alter() for 'field_ui_field_storage_add_form'.
*/
function entity_reference_form_field_ui_field_storage_add_form_alter(array &$form) {
// We cast the optgroup label to string as array keys must not be objects
// and t() may return a TranslationWrapper once issue #2557113 lands.
$optgroup = (string) t('Reference');
// Move the "Entity reference" option to the end of the list and rename it to
// "Other".
unset($form['add']['new_storage_type']['#options'][t('Reference')]['entity_reference']);
$form['add']['new_storage_type']['#options'][t('Reference')]['entity_reference'] = t('Other…');
unset($form['add']['new_storage_type']['#options'][$optgroup]['entity_reference']);
$form['add']['new_storage_type']['#options'][$optgroup]['entity_reference'] = t('Other…');
}
/**
......
......@@ -82,8 +82,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
}
else {
$language_options = array(
$this->t('Existing languages') => $existing_languages,
$this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured(),
// We cast the optgroup labels to string as array keys must not be objects
// and t() may return a TranslationWrapper once issue #2557113 lands.
(string) $this->t('Existing languages') => $existing_languages,
(string) $this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured(),
);
}
......
......@@ -94,8 +94,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
else {
$default = key($existing_languages);
$language_options = array(
$this->t('Existing languages') => $existing_languages,
$this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured(),
// We cast the optgroup labels to string as array keys must not be objects
// and t() may return a TranslationWrapper once issue #2557113 lands.
(string) $this->t('Existing languages') => $existing_languages,
(string) $this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured(),
);
}
......
......@@ -52,14 +52,18 @@ public function tokenForm(&$form, FormStateInterface $form_state) {
// Get a list of the available fields and arguments for token replacement.
$options = array();
// We cast the optgroup labels to string as array keys must not be objects
// and t() may return a TranslationWrapper once issue #2557113 lands.
$optgroup_arguments = (string) t('Arguments');
$optgroup_fields = (string) t('Fields');
foreach ($this->view->display_handler->getHandlers('field') as $field => $handler) {
$options[t('Fields')]["[$field]"] = $handler->adminLabel();
$options[$optgroup_fields]["[$field]"] = $handler->adminLabel();
}
$count = 0; // This lets us prepare the key as we want it printed.
foreach ($this->view->display_handler->getHandlers('argument') as $handler) {
$options[t('Arguments')]['%' . ++$count] = $this->t('@argument title', array('@argument' => $handler->adminLabel()));
$options[t('Arguments')]['!' . $count] = $this->t('@argument input', array('@argument' => $handler->adminLabel()));
$options[$optgroup_arguments]['%' . ++$count] = $this->t('@argument title', array('@argument' => $handler->adminLabel()));
$options[$optgroup_arguments]['!' . $count] = $this->t('@argument input', array('@argument' => $handler->adminLabel()));
}
if (!empty($options)) {
......
......@@ -1726,9 +1726,13 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$options = array();
$count = 0; // This lets us prepare the key as we want it printed.
// We cast the optgroup label to string as array keys must not be
// objects and t() may return a TranslationWrapper once issue #2557113
// lands.
$optgroup_arguments = (string) t('Arguments');
foreach ($this->view->display_handler->getHandlers('argument') as $handler) {
$options[t('Arguments')]['%' . ++$count] = $this->t('@argument title', array('@argument' => $handler->adminLabel()));
$options[t('Arguments')]['!' . $count] = $this->t('@argument input', array('@argument' => $handler->adminLabel()));
$options[$optgroup_arguments]['%' . ++$count] = $this->t('@argument title', array('@argument' => $handler->adminLabel()));
$options[$optgroup_arguments]['!' . $count] = $this->t('@argument input', array('@argument' => $handler->adminLabel()));
}
// Default text.
......
......@@ -862,19 +862,23 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
// Setup the tokens for fields.
$previous = $this->getPreviousFieldLabels();
// We cast the optgroup labels to string as array keys must not be objects
// and t() may return a TranslationWrapper once issue #2557113 lands.
$optgroup_arguments = (string) t('Arguments');
$optgroup_fields = (string) t('Fields');
foreach ($previous as $id => $label) {
$options[t('Fields')]["{{ $id }}"] = substr(strrchr($label, ":"), 2 );
$options[$optgroup_fields]["{{ $id }}"] = substr(strrchr($label, ":"), 2 );
}
// Add the field to the list of options.
$options[t('Fields')]["{{ {$this->options['id']} }}"] = substr(strrchr($this->adminLabel(), ":"), 2 );
$options[$optgroup_fields]["{{ {$this->options['id']} }}"] = substr(strrchr($this->adminLabel(), ":"), 2 );
$count = 0; // This lets us prepare the key as we want it printed.
foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
$options[t('Arguments')]['%' . ++$count] = $this->t('@argument title', array('@argument' => $handler->adminLabel()));
$options[t('Arguments')]['!' . $count] = $this->t('@argument input', array('@argument' => $handler->adminLabel()));
$options[$optgroup_arguments]['%' . ++$count] = $this->t('@argument title', array('@argument' => $handler->adminLabel()));
$options[$optgroup_arguments]['!' . $count] = $this->t('@argument input', array('@argument' => $handler->adminLabel()));
}
$this->documentSelfTokens($options[t('Fields')]);
$this->documentSelfTokens($options[$optgroup_fields]);
// Default text.
......
......@@ -92,8 +92,9 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa
}
// For easiest integration with the form API and the testing framework, we
// always give the button a unique #value, rather than playing around with
// #name.
$button_title = !empty($triggering_element['#title']) ? $triggering_element['#title'] : $trigger_key;
// #name. We also cast the #title to string as we will use it as an array
// key and it may be a TranslationWrapper.
$button_title = !empty($triggering_element['#title']) ? (string) $triggering_element['#title'] : $trigger_key;
if (empty($seen_buttons[$button_title])) {
$wrapping_element[$button_key]['#value'] = t('Update "@title" choice', array(
'@title' => $button_title,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment