improvements-2.x-dev/modules/improvements_paragraphs/src/Plugin/paragraphs/Behavior/MoveWidgetParagraphBehavior.php
modules/improvements_paragraphs/src/Plugin/paragraphs/Behavior/MoveWidgetParagraphBehavior.php
<?php
namespace Drupal\improvements_paragraphs\Plugin\paragraphs\Behavior;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\druhels\ArrayHelper;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\paragraphs\ParagraphsBehaviorBase;
/**
* @TODO Rewrite to PHP-attribute
*/
/**
* @ParagraphsBehavior(
* id = "move_widget",
* label = @Translation("Move some field widgets to behavior tab"),
* description = @Translation("Allows to move some field widgets to behavior tab."),
* weight = 104,
* )
*/
class MoveWidgetParagraphBehavior extends ParagraphsBehaviorBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration(): array {
return [
'fields' => [],
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
$form['fields'] = [
'#type' => 'textarea',
'#title' => $this->t('Fields'),
'#description' => $this->t('Format:') . ' <code>field_name|weight</code>',
'#default_value' => ArrayHelper::formatArrayAsKeyValueList($this->configuration['fields'], '|'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
$this->configuration['fields'] = ArrayHelper::formatKeyValueListAsArray($form_state->getValue('fields'), '|');
}
/**
* {@inheritdoc}
*/
public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state): array {
$form['#behavior_configuration'] = $this->configuration;
return $form;
}
/**
* {@inheritDoc}
*/
public function view(array &$build, Paragraph $paragraph, EntityViewDisplayInterface $display, $view_mode): void { }
}
