Skip to content
Snippets Groups Projects
Commit 06ce8624 authored by Florent Torregrosa's avatar Florent Torregrosa Committed by christian.wiedemann
Browse files

Issue #3409221 by Grimreaper, huzooka, Ahmad Abbad, ekes, Walli, braintec,...

Issue #3409221 by Grimreaper, huzooka, Ahmad Abbad, ekes, Walli, braintec, thejimbirch, kekkis, liber_t, kerrymick, DuaelFr, Rajab Natshah, steveoriol, catch, CarlosMonroy, very_random_man, herved: Fix TypeError: array_unshift(): Argument #1 ($array) must be of type array, null given in array_unshift() Caused by Deprecated Hooks in Drupal ~10.2.0
parent a7b01d95
No related branches found
Tags 5.x-3.1
1 merge request!27Issue #3409221: ui_patterns_settings.module - array_unshift()
......@@ -2,7 +2,7 @@ name: UI Patterns Settings
type: module
description: Configure patterns with settings
package: User interface
core_version_requirement: ^8 || ^9 || ^10
core_version_requirement: ^10.2
dependencies:
- ui_patterns:ui_patterns
- token:token
......@@ -7,6 +7,7 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Url;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\ui_patterns_settings\Plugin\PatternSettingTypeBase;
use Drupal\ui_patterns_settings\Plugin\Layout\PatternSettingsLayout;
use Drupal\Core\Entity\EntityTypeInterface;
......@@ -82,13 +83,14 @@ function ui_patterns_settings_preprocess_media_library_element(&$variables) {
}
}
/**
* Implements hook_form_field_storage_config_edit_form_alter().
* Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.
*/
function ui_patterns_settings_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state) {
function ui_patterns_settings_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state): void {
/** @var \Drupal\field\Entity\FieldStorageConfig $entity */
$entity = $form_state->getFormObject()->getEntity();
array_unshift($form['actions']['submit']['#submit'], 'ui_patterns_settings_form_field_storage_config_edit_form_submit');
$entity = $form_state->getFormObject()->getEntity()->getFieldStorageDefinition();
array_unshift($form['actions']['submit']['#submit'], 'ui_patterns_settings_form_field_config_edit_form_submit');
$definitions = UiPatterns::getPatternDefinitions();
$settings_options = [];
......@@ -98,22 +100,24 @@ function ui_patterns_settings_form_field_storage_config_edit_form_alter(&$form,
$settings_options[$key] = $info['label'];
}
}
if (count($settings_options) > 0) {
$parent = &$form['field_storage']['subform'];
$mapping = UiPatternsSettings::getConfigManager()->getMapping($entity->id());
$form['settings']['use_pattern'] = [
$parent['settings']['use_pattern'] = [
'#type' => 'checkbox',
'#title' => t('Expose pattern setting'),
'#default_value' => $mapping !== NULL,
'#description' => '',
];
$form['settings']['pattern_setting'] = [
$parent['settings']['pattern_setting'] = [
'#type' => 'select',
'#options' => $settings_options,
'#title' => 'Pattern Setting',
'#states' => [
'invisible' => [
':input[name="settings[use_pattern]"]' => ['checked' => FALSE],
':input[name$="[use_pattern]"]' => ['checked' => FALSE],
],
],
'#default_value' => $mapping,
......@@ -122,12 +126,12 @@ function ui_patterns_settings_form_field_storage_config_edit_form_alter(&$form,
}
/**
* Implements hook_form_field_storage_config_edit_form_submit().
* Form submit callback.
*/
function ui_patterns_settings_form_field_storage_config_edit_form_submit(array $form, FormStateInterface $form_state) {
$settings = $form_state->getValue('settings');
/** @var \Drupal\field\Entity\FieldStorageConfig $entity */
$entity = $form_state->getFormObject()->getEntity();
function ui_patterns_settings_form_field_config_edit_form_submit(array $form, FormStateInterface $form_state) {
$settings = $form_state->getValue(['field_storage', 'subform', 'settings']);
$entity = $form_state->getFormObject()->getEntity()->getFieldStorageDefinition();
\assert($entity instanceof FieldStorageConfigInterface);
if (isset($settings['use_pattern']) && $settings['use_pattern'] === 1) {
UiPatternsSettings::getConfigManager()->addMapping($entity->id(), $settings['pattern_setting']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment