Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / paragraphs / src / Form / ParagraphsTypeForm.php
index d17551907c41ee22fd19a6928018c573af736e87..03d427d6fceb3fbd97aebb8a188758912d82bfec 100644 (file)
@@ -76,9 +76,30 @@ class ParagraphsTypeForm extends EntityForm {
       '#machine_name' => array(
         'exists' => 'paragraphs_type_load',
       ),
+      '#maxlength' => 32,
       '#disabled' => !$paragraphs_type->isNew(),
     );
 
+    $form['icon_file'] = [
+      '#title' => $this->t('Paragraph type icon'),
+      '#type' => 'managed_file',
+      '#upload_location' => 'public://paragraphs_type_icon/',
+      '#upload_validators' => [
+        'file_validate_extensions' => ['png jpg svg'],
+      ],
+    ];
+
+    if ($file = $this->entity->getIconFile()) {
+      $form['icon_file']['#default_value'] = ['target_id' => $file->id()];
+    }
+
+    $form['description'] = [
+      '#title' => t('Description'),
+      '#type' => 'textarea',
+      '#default_value' => $paragraphs_type->getDescription(),
+      '#description' => t('This text will be displayed on the <em>Add new paragraph</em> page.'),
+    ];
+
     // Loop over the plugins that can be applied to this paragraph type.
     if ($behavior_plugin_definitions = $this->paragraphsBehaviorManager->getApplicableDefinitions($paragraphs_type)) {
       $form['message'] = [
@@ -130,6 +151,15 @@ class ParagraphsTypeForm extends EntityForm {
 
     $paragraphs_type = $this->entity;
 
+    $icon_fild = $form_state->getValue(['icon_file', '0']);
+    // Set the file UUID to the paragraph configuration.
+    if (!empty($icon_fild) && $file = $this->entityTypeManager->getStorage('file')->load($icon_fild)) {
+      $paragraphs_type->set('icon_uuid', $file->uuid());
+    }
+    else {
+      $paragraphs_type->set('icon_uuid', NULL);
+    }
+
     if ($behavior_plugin_definitions = $this->paragraphsBehaviorManager->getApplicableDefinitions($paragraphs_type)) {
       foreach ($behavior_plugin_definitions as $id => $behavior_plugin_definition) {
         // Only validate if the plugin is enabled and has settings.