Issue #3517695 by smovs, christian.wiedemann: [2.0.x] UI Patterns UI - Field widget for UI Patterns field
Closes #3517695
Merge request reports
Activity
added 1 commit
- 93cfbc60 - 3517695 - Fixed phpstan errors in the ComponentFormDisplayWidget.
added 1 commit
- 7fac600a - 3517695 - Fixed phpstan errors in the ComponentFormDisplayWidget.
141 $item_delta_value = $items[$delta]->getValue() ?? []; 142 $source_id = $item_delta_value['source_id'] ?? 'component'; 143 144 if ($source_id !== 'component') { 145 // The widget can only deal with component sources. 146 // To make sure no data will be overwritten we disable the widget. 147 $element['#access'] = FALSE; 148 return $element; 149 } 150 151 $settings = $this->getSettings() ?? []; 152 $display_id = $settings['display_id'] ?? NULL; 153 $component_id = NULL; 154 $form_display = NULL; 155 156 if ($display_id) { changed this line in version 4 of the diff
148 return $element; 149 } 150 151 $settings = $this->getSettings() ?? []; 152 $display_id = $settings['display_id'] ?? NULL; 153 $component_id = NULL; 154 $form_display = NULL; 155 156 if ($display_id) { 157 $form_display = $this->entityTypeManager 158 ->getStorage('component_form_display') 159 ->load($display_id); 160 } 161 162 if ($form_display instanceof ComponentFormDisplay) { 163 $component_id = $form_display->getComponentId(); changed this line in version 4 of the diff
163 $component_id = $form_display->getComponentId(); 164 } 165 166 $source_data = $item_delta_value["source"] ?? []; 167 $component_default_value = $source_data['component'] ?? 168 ['#component_id' => $component_id, '#display_id' => $display_id]; 169 170 $element['source'] = [ 171 '#type' => 'container', 172 '#tree' => TRUE, 173 'source_id' => ['#type' => 'hidden', '#value' => 'component'], 174 'component' => ['#type' => 'uip_display_form', '#default_value' => $component_default_value], 175 ]; 176 177 $contexts = $this->getComponentSourceContexts($items); 178 $element['source']["component"] = $this->buildComponentsForm($form_state, $contexts, $component_id, TRUE, TRUE, 'ui_patterns'); changed this line in version 4 of the diff
Indeed. The 'component' was immediately overridden, and it didn't make sense. I refactored that, but still not sure if it is a good approach. See /ui_patterns/modules/ui_patterns_ui/src/Plugin/Field/FieldWidget/ComponentFormDisplayWidget.php:184
Probably, can we use something like that?
$this->buildComponentsForm($form_state, $contexts, $component_id, TRUE, TRUE, 'uip_display_form', $component_default_value);
1 <?php 2 3 namespace Drupal\ui_patterns_field\Plugin\Field\FieldWidget; changed this line in version 4 of the diff
9 use Drupal\Core\Form\FormStateInterface; 10 use Drupal\Core\Plugin\Context\Context; 11 use Drupal\Core\Plugin\Context\ContextDefinition; 12 use Drupal\Core\Plugin\Context\EntityContext; 13 use Drupal\Core\StringTranslation\TranslatableMarkup; 14 use Drupal\Core\Theme\ComponentPluginManager; 15 use Drupal\ui_patterns\Form\ComponentFormBuilderTrait; 16 use Drupal\ui_patterns\Plugin\Context\RequirementsContext; 17 use Drupal\ui_patterns_ui\Entity\ComponentFormDisplay; 18 use Symfony\Component\DependencyInjection\ContainerInterface; 19 20 /** 21 * Field widget for a predefined component display form. 22 */ 23 #[FieldWidget( 24 id: "ui_patterns_component_form_display", changed this line in version 4 of the diff
10 use Drupal\Core\Plugin\Context\Context; 11 use Drupal\Core\Plugin\Context\ContextDefinition; 12 use Drupal\Core\Plugin\Context\EntityContext; 13 use Drupal\Core\StringTranslation\TranslatableMarkup; 14 use Drupal\Core\Theme\ComponentPluginManager; 15 use Drupal\ui_patterns\Form\ComponentFormBuilderTrait; 16 use Drupal\ui_patterns\Plugin\Context\RequirementsContext; 17 use Drupal\ui_patterns_ui\Entity\ComponentFormDisplay; 18 use Symfony\Component\DependencyInjection\ContainerInterface; 19 20 /** 21 * Field widget for a predefined component display form. 22 */ 23 #[FieldWidget( 24 id: "ui_patterns_component_form_display", 25 label: new TranslatableMarkup("Component Display Form (UI Patterns)"), changed this line in version 4 of the diff
64 } 65 66 /** 67 * Get the display mode options. 68 * 69 * @return array 70 * Display mode options. 71 */ 72 protected function getFormModeOptions(): array { 73 $options = []; 74 75 $form_displays = $this->entityTypeManager 76 ->getStorage('component_form_display') 77 ->loadMultiple(); 78 79 foreach ($form_displays as $id => $form_display) { changed this line in version 4 of the diff
85 86 return $options; 87 } 88 89 /** 90 * {@inheritdoc} 91 */ 92 public function settingsForm(array $form, FormStateInterface $form_state): array { 93 $options = $this->getFormModeOptions(); 94 $element = []; 95 96 $element['display_id'] = [ 97 '#type' => 'select', 98 '#title' => $this->t('Display ID'), 99 '#default_value' => $this->getSetting('display_id'), 100 '#required' => FALSE, changed this line in version 4 of the diff
added 1 commit
added 10 commits
-
709ce677...4d6ff5a7 - 4 commits from branch
project:2.0.x
- 0f51e47b - 3517695 - Created ComponentFormDisplayWidget in ui_patterns_field module.
- 1a7672e1 - 3517695 - Fixed phpstan errors in the ComponentFormDisplayWidget.
- d348c0a6 - 3517695 - Fixed phpstan errors in the ComponentFormDisplayWidget.
- 1b65a8f6 - #3517695 - Refactored ComponentFormDisplayWidget.
- d6493740 - Add additional display ids
- fbf3f2c1 - escape settings source
Toggle commit list-
709ce677...4d6ff5a7 - 4 commits from branch
enabled an automatic merge when all merge checks for fbf3f2c1 pass