class ParagraphsDemoUserToTextUser

Provides a Paragraphs conversion plugin.

Plugin annotation


@ParagraphsConversion(
  id = "paragraphs_demo_user_to_text_user",
  label = @Translation("Convert to Text and User"),
  source_type = "user",
  target_types = {"text", "user"},
  weight = 0
)

Hierarchy

Expanded class hierarchy of ParagraphsDemoUserToTextUser

File

paragraphs/modules/paragraphs_demo/src/Plugin/paragraphs/Conversion/ParagraphsDemoUserToTextUser.php, line 19

Namespace

Drupal\paragraphs_demo\Plugin\paragraphs\Conversion
View source
class ParagraphsDemoUserToTextUser extends ParagraphsConversionBase {

  /**
   * {@inheritdoc}
   */
  public function convert(array $settings, ParagraphInterface $original_paragraph, array $converted_paragraphs = NULL) {
    $username = "Empty user field";
    $user = NULL;
    if ($original_paragraph
      ->get('field_user_demo')->entity) {
      $username = $original_paragraph
        ->get('field_user_demo')->entity
        ->label();
      $user = $original_paragraph
        ->get('field_user_demo')->entity;
    }
    return [
      [
        'type' => 'text',
        'field_text_demo' => [
          'value' => $username,
        ],
      ],
      [
        'type' => 'user',
        'field_user_demo' => $user ?: NULL,
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsConversionBase::buildConfigurationForm public function
ParagraphsConversionBase::buildConversionForm public function Builds a conversion form to add extra settings to the conversion. Overrides ParagraphsConversionInterface::buildConversionForm 1
ParagraphsConversionBase::calculateDependencies public function
ParagraphsConversionBase::create public static function
ParagraphsConversionBase::defaultConfiguration public function
ParagraphsConversionBase::getConfiguration public function
ParagraphsConversionBase::setConfiguration public function
ParagraphsConversionBase::submitConfigurationForm public function
ParagraphsConversionBase::supports public function Check if the current plugin supports conversion for a paragraph. Overrides ParagraphsConversionInterface::supports
ParagraphsConversionBase::validateConfigurationForm public function
ParagraphsConversionBase::validateConversionForm public function Validates the conversion fields form. Overrides ParagraphsConversionInterface::validateConversionForm
ParagraphsConversionBase::__construct public function Constructs a ParagraphsBehaviorBase object.
ParagraphsDemoUserToTextUser::convert public function Submit the values taken from the form to store the values. Overrides ParagraphsConversionBase::convert