Skip to content
Snippets Groups Projects

Issue #3517695 by smovs, christian.wiedemann: [2.0.x] UI Patterns UI - Field widget for UI Patterns field

Merged Issue #3517695 by smovs, christian.wiedemann: [2.0.x] UI Patterns UI - Field widget for UI Patterns field
8 unresolved threads
8 unresolved threads

Closes #3517695

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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) {
  • 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();
  • 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');
  • 1 <?php
    2
    3 namespace Drupal\ui_patterns_field\Plugin\Field\FieldWidget;
  • 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",
  • 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)"),
  • 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) {
  • 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,
  • christian.wiedemann left review comments

    left review comments

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • 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

    Compare with previous version

  • christian.wiedemann enabled an automatic merge when all merge checks for fbf3f2c1 pass

    enabled an automatic merge when all merge checks for fbf3f2c1 pass

  • christian.wiedemann canceled the automatic merge

    canceled the automatic merge

  • christian.wiedemann changed title from 3517695 - Created ComponentFormDisplayWidget in ui_patterns_field module. to Issue #3517695 by smovs, christian.wiedemann: [2.0.x] UI Patterns UI - Field widget for UI Patterns field
    changed title from 3517695 - Created ComponentFormDisplayWidget in ui_patterns_field module. to Issue #3517695 by smovs, christian.wiedemann: [2.0.x] UI Patterns UI - Field widget for UI Patterns field
  • Please register or sign in to reply
    Loading