020414f43fe59e7bb0c44fde5df9bc396ff7adfe
[yaffs-website] / web / modules / contrib / media_entity / src / Form / MediaInlineForm.php
1 <?php
2
3 namespace Drupal\media_entity\Form;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\StringTranslation\StringTranslationTrait;
7 use Drupal\inline_entity_form\Form\EntityInlineForm;
8
9 /**
10  * Media inline form handler.
11  */
12 class MediaInlineForm extends EntityInlineForm {
13
14   use StringTranslationTrait;
15
16   /**
17    * {@inheritdoc}
18    */
19   public function getTableFields($bundles) {
20     $fields = parent::getTableFields($bundles);
21
22     unset($fields['name']);
23
24     $fields['thumbnail'] = [
25       'type' => 'field',
26       'label' => $this->t('Thumbnail'),
27       'weight' => 1,
28       'display_options' => [
29         'type' => 'image',
30         'settings' => [
31           'image_style' => 'thumbnail',
32         ],
33       ],
34     ];
35
36     return $fields;
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function entityFormSubmit(array &$entity_form, FormStateInterface $form_state) {
43     parent::entityFormSubmit($entity_form, $form_state);
44
45     /** @var \Drupal\media_entity\MediaInterface $entity */
46     $entity = $entity_form['#entity'];
47
48     // Make sure media thumbnail is set correctly.
49     $entity->automaticallySetThumbnail();
50
51     if ($entity_form['#save_entity']) {
52       $entity->save();
53     }
54   }
55
56 }