<?php
namespace Drupal\paragraphs;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a base class for paragraphs conversions.
*/
abstract class ParagraphsConversionBase extends PluginBase implements ParagraphsConversionInterface, ContainerFactoryPluginInterface {
/**
* Constructs a ParagraphsBehaviorBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configuration += $this
->defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this
->defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function buildConversionForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
return [];
}
/**
* {@inheritdoc}
*/
public function validateConversionForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function convert(array $settings, ParagraphInterface $original_paragraph, array $converted_paragraph = NULL) {
return NULL;
}
/**
* {@inheritdoc}
*/
public function supports(ParagraphInterface $paragraph, array $parent_allowed_types = NULL) {
return $paragraph
->getType() == $this
->getPluginDefinition()['source_type'];
}
}
Name | Description |
---|---|
ParagraphsConversionBase | Provides a base class for paragraphs conversions. |