Settings UI
Closes #3425144
Merge request reports
Activity
added 2 commits
added 1 commit
- ade3c2af - Force required only in case enabled was ticked.
- src/Form/Alter/BundleEntityFormAlter.php 0 → 100644
12 use Drupal\Core\Form\FormStateInterface; 13 use Symfony\Component\DependencyInjection\ContainerInterface; 14 15 /** 16 * Bundle entity form alter. 17 */ 18 class BundleEntityFormAlter extends AbstractFormAlter implements ContainerInjectionInterface { 19 20 /** 21 * Constructs BundleEntityFormAlter instance. 22 * 23 * @param \Drupal\Component\Plugin\PluginManagerInterface $uriGeneratorPluginManager 24 * Plugin manager. 25 * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager 26 * Entity field manager. 27 */ - Comment on lines +20 to +27
This is just a side-note because is relatively new rule: constructor docblock can be omitted (but you may also keep it)
See:
- src/Form/Alter/BundleEntityFormAlter.php 0 → 100644
68 69 $form['rdf_sync']['enabled'] = [ 70 '#type' => 'checkbox', 71 '#default_value' => !empty($settings['type']), 72 '#title' => $this->t('Enable RDF sync'), 73 ]; 74 75 $form['rdf_sync']['type'] = [ 76 '#type' => 'url', 77 '#title' => $this->t('RDF type mapping'), 78 '#default_value' => $settings['type'] ?? '', 79 '#states' => $hideStates + 80 ['required' => $hideStates['visible']], 81 ]; 82 83 $form['rdf_sync']['uri_field_name'] = [ - src/Form/Alter/BundleEntityFormAlter.php 0 → 100644
78 '#default_value' => $settings['type'] ?? '', 79 '#states' => $hideStates + 80 ['required' => $hideStates['visible']], 81 ]; 82 83 $form['rdf_sync']['uri_field_name'] = [ 84 '#type' => 'textfield', 85 '#title' => $this->t('URI field name'), 86 '#default_value' => $settings['uri_field_name'] ?? '', 87 '#states' => $hideStates, 88 ]; 89 90 $form['rdf_sync']['uri_plugin'] = [ 91 '#type' => 'select', 92 '#title' => $this->t('URI generator plugin ID'), 93 '#default_value' => $settings['uri_plugin'] ?? '', - src/Form/Alter/BundleEntityFormAlter.php 0 → 100644
146 $result[$item['id']] = $item['name']; 147 return $result; 148 }, []); 149 } 150 151 /** 152 * Gets field columns. 153 * 154 * @param \Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition 155 * Field definition. 156 * 157 * @return array 158 * Columns. 159 */ 160 protected function getColumnFields(FieldDefinitionInterface $fieldDefinition): array { 161 if ($fieldDefinition->isComputed() || empty($fieldDefinition->getColumns())) { changed this line in version 10 of the diff
- src/Form/Alter/BundleEntityFormAlter.php 0 → 100644
151 /** 152 * Gets field columns. 153 * 154 * @param \Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition 155 * Field definition. 156 * 157 * @return array 158 * Columns. 159 */ 160 protected function getColumnFields(FieldDefinitionInterface $fieldDefinition): array { 161 if ($fieldDefinition->isComputed() || empty($fieldDefinition->getColumns())) { 162 return []; 163 } 164 165 $columns = array_keys($fieldDefinition->getColumns()); 166 if (in_array($fieldDefinition->getType(), [ changed this line in version 10 of the diff
- src/Form/Alter/BundleEntityFormAlter.php 0 → 100644
120 121 foreach ($fieldColumns as $column) { 122 $fieldSettings = $settings['fields'][$baseField->getName()][$column] ?? []; 123 124 $form['rdf_sync']['base_fields_mapping'][$baseField->getName()][$column] = [ 125 '#type' => 'details', 126 '#title' => $column, 127 '#open' => TRUE, 128 ]; 129 130 $form['rdf_sync']['base_fields_mapping'][$baseField->getName()][$column]['predicate'] = $this->getPredicateElement($fieldSettings); 131 $form['rdf_sync']['base_fields_mapping'][$baseField->getName()][$column]['type'] = $this->getTypeElement($fieldSettings); 132 } 133 } 134 135 $form['#entity_builders'][] = [$this, 'entityFormEntityBuild']; What is in EntityOperations::entityFormAlter()? I do not see any important thing in.
Edited by Adrian Lorenc
- src/Form/Alter/BundleEntityFormAlter.php 0 → 100644
77 '#title' => $this->t('RDF type mapping'), 78 '#default_value' => $settings['type'] ?? '', 79 '#states' => $hideStates + 80 ['required' => $hideStates['visible']], 81 ]; 82 83 $form['rdf_sync']['uri_field_name'] = [ 84 '#type' => 'textfield', 85 '#title' => $this->t('URI field name'), 86 '#default_value' => $settings['uri_field_name'] ?? '', 87 '#states' => $hideStates, 88 ]; 89 90 $form['rdf_sync']['uri_plugin'] = [ 91 '#type' => 'select', 92 '#title' => $this->t('URI generator plugin ID'), Updated but this was copied from the scheme label.
Edited by Adrian Lorencchanged this line in version 11 of the diff
- src/Form/Alter/BundleEntityFormAlter.php 0 → 100644
41 $container->get('entity_field.manager'), 42 ); 43 } 44 45 /** 46 * {@inheritdoc} 47 */ 48 public function alter(array &$form, FormStateInterface $formState): void { 49 /** @var \Drupal\Core\Entity\BundleEntityFormBase $bundleEntity */ 50 $bundleEntity = $formState->getFormObject(); 51 /** @var \Drupal\Core\Config\Entity\ConfigEntityBundleBase $configEntity */ 52 $configEntity = $bundleEntity->getEntity(); 53 54 $settings = $configEntity->getThirdPartySettings('rdf_sync'); 55 56 $form['rdf_sync'] = [ Probably if you started from
$form['third_party_settings']['rdf_sync']
and aded#tree => TRUE
, it would had saved a lot of code, specifically the need for an entity builder. Then any value changes, like var casting ('' > NULL) or clearing the empty base field mapping, would have been handled in a validation callback. However, I'm not saying to change the current approach, let's keep it as it is.
- Resolved by Adrian Lorenc
- Resolved by Adrian Lorenc