Loading designs.services.yml +5 −0 Changes for designs.services.yml: 5 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -19,3 +19,8 @@ services: plugin.manager.design_source: class: Drupal\designs\DesignSourceManager parent: default_plugin_manager design.properties: class: Drupal\designs\DesignProperties arguments: - '@entity_type.manager' - '@renderer' modules/designs_field/src/Plugin/designs/source/FieldItemWrapperSource.php +14 −31 Changes for modules/designs_field/src/Plugin/designs/source/FieldItemWrapperSource.php: 14 added lines, 31 removed lines. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\Context\EntityContextDefinition; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\designs\DesignPropertiesInterface; use Drupal\designs\DesignSourceBase; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -39,13 +40,21 @@ class FieldItemWrapperSource extends DesignSourceBase implements ContainerFactor */ protected $fieldTypeManager; /** * The design properties. * * @var \Drupal\designs\DesignPropertiesInterface */ protected $designProperties; /** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $entityFieldManager, FieldTypePluginManagerInterface $fieldTypeManager) { public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $entityFieldManager, FieldTypePluginManagerInterface $fieldTypeManager, DesignPropertiesInterface $designProperties) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityFieldManager = $entityFieldManager; $this->fieldTypeManager = $fieldTypeManager; $this->designProperties = $designProperties; } /** Loading @@ -57,7 +66,8 @@ class FieldItemWrapperSource extends DesignSourceBase implements ContainerFactor $plugin_id, $plugin_definition, $container->get('entity_field.manager'), $container->get('plugin.manager.field.field_type') $container->get('plugin.manager.field.field_type'), $container->get('design.properties') ); } Loading Loading @@ -116,40 +126,13 @@ class FieldItemWrapperSource extends DesignSourceBase implements ContainerFactor // Cycle through all the properties for the field type. $definition = $this->getType()->getDataDefinition(); foreach ($definition->getPropertyDefinitions() as $prop_id => $property) { $output[$prop_id] = $this->getMarkup($item->get($prop_id)->getValue()); $output[$prop_id] = $this->designProperties->getMarkup($item->get($prop_id) ->getValue()); } return $output; } /** * Get the markup from the value. * * @param mixed $value * A property value. * * @return array * The render array. */ protected function getMarkup($value) { if (is_scalar($value)) { return [ '#markup' => $value, ]; } elseif (method_exists($value, 'toString')) { return [ '#markup' => $value->toString(), ]; } elseif (method_exists($value, '__toString')) { return [ '#markup' => (string) $value, ]; } return []; } /** * {@inheritdoc} */ Loading modules/designs_field_formatter/src/Plugin/designs/source/FieldFormatterSource.php +14 −35 Changes for modules/designs_field_formatter/src/Plugin/designs/source/FieldFormatterSource.php: 14 added lines, 35 removed lines. Original line number Diff line number Diff line Loading @@ -2,12 +2,12 @@ namespace Drupal\designs_field_formatter\Plugin\designs\source; use Drupal\Core\Entity\Display\EntityDisplayInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\Context\EntityContextDefinition; use Drupal\Core\TypedData\ComplexDataDefinitionInterface; use Drupal\designs\DesignPropertiesInterface; use Drupal\designs\DesignSourceBase; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -42,13 +42,21 @@ class FieldFormatterSource extends DesignSourceBase implements ContainerFactoryP */ protected $fieldTypeManager; /** * The design properties. * * @var \Drupal\designs\DesignPropertiesInterface */ protected $designProperties; /** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $entityFieldManager, FieldTypePluginManagerInterface $fieldTypeManager) { public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $entityFieldManager, FieldTypePluginManagerInterface $fieldTypeManager, DesignPropertiesInterface $designProperties) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityFieldManager = $entityFieldManager; $this->fieldTypeManager = $fieldTypeManager; $this->designProperties = $designProperties; } /** Loading @@ -60,7 +68,8 @@ class FieldFormatterSource extends DesignSourceBase implements ContainerFactoryP $plugin_id, $plugin_definition, $container->get('entity_field.manager'), $container->get('plugin.manager.field.field_type') $container->get('plugin.manager.field.field_type'), $container->get('design.properties') ); } Loading Loading @@ -114,43 +123,13 @@ class FieldFormatterSource extends DesignSourceBase implements ContainerFactoryP // Cycle through all the properties for the field type. $definition = $this->getType()->getDataDefinition(); foreach ($definition->getPropertyDefinitions() as $prop_id => $property) { $output[$prop_id] = $this->getMarkup($item->get($prop_id)->getValue()); $output[$prop_id] = $this->designProperties->getMarkup($item->get($prop_id) ->getValue()); } return $output; } /** * Get the markup from the value. * * @param mixed $value * A property value. * * @return array * The render array. */ protected function getMarkup($value) { if (is_null($value)) { return ['#markup' => '']; } elseif (is_scalar($value)) { return [ '#markup' => $value, ]; } elseif (method_exists($value, 'toString')) { return [ '#markup' => $value->toString(), ]; } elseif (method_exists($value, '__toString')) { return [ '#markup' => (string) $value, ]; } return []; } /** * {@inheritdoc} */ Loading src/DesignProperties.php 0 → 100644 +73 −0 Changes for src/DesignProperties.php: 73 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\designs; use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Render\RendererInterface; /** * Helper class used for data type properties. */ class DesignProperties implements DesignPropertiesInterface { /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * The renderer. * * @var \Drupal\Core\Render\RendererInterface */ protected $renderer; /** * DesignProperties constructor. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * The entity type manager. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. */ public function __construct(EntityTypeManagerInterface $entityTypeManager, RendererInterface $renderer) { $this->entityTypeManager = $entityTypeManager; $this->renderer = $renderer; } /** * {@inheritdoc} */ public function getMarkup($value) { if (is_null($value)) { return ['#markup' => '']; } elseif (is_scalar($value)) { return [ '#markup' => $value, ]; } elseif (method_exists($value, 'toString')) { return [ '#markup' => $value->toString(), ]; } elseif (method_exists($value, '__toString')) { return [ '#markup' => (string) $value, ]; } elseif ($value instanceof ContentEntityBase) { $view_builder = $this->entityTypeManager->getViewBuilder($value->getEntityTypeId()); $view = $view_builder->view($value); return [ '#markup' => $this->renderer->render($view), ]; } return []; } } src/DesignPropertiesInterface.php 0 → 100644 +21 −0 Changes for src/DesignPropertiesInterface.php: 21 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\designs; /** * Interface for the design properties service. */ interface DesignPropertiesInterface { /** * Get the markup from the property value. * * @param mixed $value * A property value. * * @return array * The render array. */ public function getMarkup($value); } Loading
designs.services.yml +5 −0 Changes for designs.services.yml: 5 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -19,3 +19,8 @@ services: plugin.manager.design_source: class: Drupal\designs\DesignSourceManager parent: default_plugin_manager design.properties: class: Drupal\designs\DesignProperties arguments: - '@entity_type.manager' - '@renderer'
modules/designs_field/src/Plugin/designs/source/FieldItemWrapperSource.php +14 −31 Changes for modules/designs_field/src/Plugin/designs/source/FieldItemWrapperSource.php: 14 added lines, 31 removed lines. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\Context\EntityContextDefinition; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\designs\DesignPropertiesInterface; use Drupal\designs\DesignSourceBase; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -39,13 +40,21 @@ class FieldItemWrapperSource extends DesignSourceBase implements ContainerFactor */ protected $fieldTypeManager; /** * The design properties. * * @var \Drupal\designs\DesignPropertiesInterface */ protected $designProperties; /** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $entityFieldManager, FieldTypePluginManagerInterface $fieldTypeManager) { public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $entityFieldManager, FieldTypePluginManagerInterface $fieldTypeManager, DesignPropertiesInterface $designProperties) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityFieldManager = $entityFieldManager; $this->fieldTypeManager = $fieldTypeManager; $this->designProperties = $designProperties; } /** Loading @@ -57,7 +66,8 @@ class FieldItemWrapperSource extends DesignSourceBase implements ContainerFactor $plugin_id, $plugin_definition, $container->get('entity_field.manager'), $container->get('plugin.manager.field.field_type') $container->get('plugin.manager.field.field_type'), $container->get('design.properties') ); } Loading Loading @@ -116,40 +126,13 @@ class FieldItemWrapperSource extends DesignSourceBase implements ContainerFactor // Cycle through all the properties for the field type. $definition = $this->getType()->getDataDefinition(); foreach ($definition->getPropertyDefinitions() as $prop_id => $property) { $output[$prop_id] = $this->getMarkup($item->get($prop_id)->getValue()); $output[$prop_id] = $this->designProperties->getMarkup($item->get($prop_id) ->getValue()); } return $output; } /** * Get the markup from the value. * * @param mixed $value * A property value. * * @return array * The render array. */ protected function getMarkup($value) { if (is_scalar($value)) { return [ '#markup' => $value, ]; } elseif (method_exists($value, 'toString')) { return [ '#markup' => $value->toString(), ]; } elseif (method_exists($value, '__toString')) { return [ '#markup' => (string) $value, ]; } return []; } /** * {@inheritdoc} */ Loading
modules/designs_field_formatter/src/Plugin/designs/source/FieldFormatterSource.php +14 −35 Changes for modules/designs_field_formatter/src/Plugin/designs/source/FieldFormatterSource.php: 14 added lines, 35 removed lines. Original line number Diff line number Diff line Loading @@ -2,12 +2,12 @@ namespace Drupal\designs_field_formatter\Plugin\designs\source; use Drupal\Core\Entity\Display\EntityDisplayInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\Context\EntityContextDefinition; use Drupal\Core\TypedData\ComplexDataDefinitionInterface; use Drupal\designs\DesignPropertiesInterface; use Drupal\designs\DesignSourceBase; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -42,13 +42,21 @@ class FieldFormatterSource extends DesignSourceBase implements ContainerFactoryP */ protected $fieldTypeManager; /** * The design properties. * * @var \Drupal\designs\DesignPropertiesInterface */ protected $designProperties; /** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $entityFieldManager, FieldTypePluginManagerInterface $fieldTypeManager) { public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $entityFieldManager, FieldTypePluginManagerInterface $fieldTypeManager, DesignPropertiesInterface $designProperties) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityFieldManager = $entityFieldManager; $this->fieldTypeManager = $fieldTypeManager; $this->designProperties = $designProperties; } /** Loading @@ -60,7 +68,8 @@ class FieldFormatterSource extends DesignSourceBase implements ContainerFactoryP $plugin_id, $plugin_definition, $container->get('entity_field.manager'), $container->get('plugin.manager.field.field_type') $container->get('plugin.manager.field.field_type'), $container->get('design.properties') ); } Loading Loading @@ -114,43 +123,13 @@ class FieldFormatterSource extends DesignSourceBase implements ContainerFactoryP // Cycle through all the properties for the field type. $definition = $this->getType()->getDataDefinition(); foreach ($definition->getPropertyDefinitions() as $prop_id => $property) { $output[$prop_id] = $this->getMarkup($item->get($prop_id)->getValue()); $output[$prop_id] = $this->designProperties->getMarkup($item->get($prop_id) ->getValue()); } return $output; } /** * Get the markup from the value. * * @param mixed $value * A property value. * * @return array * The render array. */ protected function getMarkup($value) { if (is_null($value)) { return ['#markup' => '']; } elseif (is_scalar($value)) { return [ '#markup' => $value, ]; } elseif (method_exists($value, 'toString')) { return [ '#markup' => $value->toString(), ]; } elseif (method_exists($value, '__toString')) { return [ '#markup' => (string) $value, ]; } return []; } /** * {@inheritdoc} */ Loading
src/DesignProperties.php 0 → 100644 +73 −0 Changes for src/DesignProperties.php: 73 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\designs; use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Render\RendererInterface; /** * Helper class used for data type properties. */ class DesignProperties implements DesignPropertiesInterface { /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * The renderer. * * @var \Drupal\Core\Render\RendererInterface */ protected $renderer; /** * DesignProperties constructor. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * The entity type manager. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. */ public function __construct(EntityTypeManagerInterface $entityTypeManager, RendererInterface $renderer) { $this->entityTypeManager = $entityTypeManager; $this->renderer = $renderer; } /** * {@inheritdoc} */ public function getMarkup($value) { if (is_null($value)) { return ['#markup' => '']; } elseif (is_scalar($value)) { return [ '#markup' => $value, ]; } elseif (method_exists($value, 'toString')) { return [ '#markup' => $value->toString(), ]; } elseif (method_exists($value, '__toString')) { return [ '#markup' => (string) $value, ]; } elseif ($value instanceof ContentEntityBase) { $view_builder = $this->entityTypeManager->getViewBuilder($value->getEntityTypeId()); $view = $view_builder->view($value); return [ '#markup' => $this->renderer->render($view), ]; } return []; } }
src/DesignPropertiesInterface.php 0 → 100644 +21 −0 Changes for src/DesignPropertiesInterface.php: 21 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\designs; /** * Interface for the design properties service. */ interface DesignPropertiesInterface { /** * Get the markup from the property value. * * @param mixed $value * A property value. * * @return array * The render array. */ public function getMarkup($value); }