Skip to content
Snippets Groups Projects

Settings UI

8 open threads

Closes #3425144

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
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 */
  • 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'] = [
  • 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'] ?? '',
    • Because RdfUriGeneratorPluginManager extends FallbackPluginManagerInterface, we should:

      • Remove the default plugin from the list
      • Set #empty_option to - default -
      • When saving, and the value is empty, we should make sure we don't add uri_plugin to the config
    • It does not make sense to me to set empty to default and not save this value.

    • Please register or sign in to reply
  • 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())) {
  • 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(), [
  • 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'];
  • 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'),
  • 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.

    • Please register or sign in to reply
  • Claudiu Cristea
  • Claudiu Cristea
  • Adrian Lorenc added 4 commits

    added 4 commits

    Compare with previous version

  • Adrian Lorenc added 1 commit

    added 1 commit

    Compare with previous version

  • Adrian Lorenc added 1 commit

    added 1 commit

    • e93b1eb4 - Default is not longer aviable.

    Compare with previous version

  • Claudiu Cristea approved this merge request

    approved this merge request

  • Please register or sign in to reply
    Loading