Rethink DsField settings

Created on 13 May 2016, about 8 years ago
Updated 23 December 2023, 6 months ago

Background:
I tried to add Ds integration for product variation fields ( ✨ Add Display Suite integration for variation fields Closed: won't fix ).
Commerce has products made out of variations. We need to derive a DsField plugin for each renderable variation field, so that they're available on the product form display. These variation fields have the same formatters and settings as on their original manage display form.
I failed to complete this task.

Problems:
- render() doesn't have access to the 'label' setting
- methods don't have access to the selected formatter
- The relationship between plugin specific configuration and general configuration is very unclear.

Ds::getFieldInstance has this code that is very unclear to me, because it passes $configuration them immediately overrides it:

  $configuration = array(
      'field' => $field,
      'field_name' => $key,
      'entity' => $entity,
      'build' => $build,
      'view_mode' => $view_mode,
    );

    // Load the plugin.
    /** @var $field_instance \Drupal\ds\Plugin\DsField\DsFieldInterface */
    $field_instance = \Drupal::service('plugin.manager.ds')->createInstance($field['plugin_id'], $configuration);

    /** @var $display EntityDisplayInterface */
    if ($field_settings = $display->getThirdPartySetting('ds', 'fields')) {
      $settings = isset($field_settings[$key]['settings']) ? $field_settings[$key]['settings'] : array();
      // Unset field template settings.
      if (isset($settings['ft'])) {
        unset($settings['ft']);
      }

      $field_instance->setConfiguration($settings);
    }

I think that $configuration should always be the plugin specific configuration, it should not contain any other information.
The view mode, entity, formatter, label setting should all be injected separately (call it $context or whatever).

πŸ“Œ Task
Status

Closed: outdated

Version

3.0

Component

Code

Created by

πŸ‡·πŸ‡ΈSerbia bojanz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡ͺBelgium swentel

    Extremely late to the party here :)

    We've used DS on products quite a lot, so I think (at least nowadays), we're fine.

    If I need to look at something specific, please let me know and I can have a look and see what's missing, but tentatively closing this one for now.

Production build 0.69.0 2024