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).