setQueueThumbnailDownloadsStatus example


    $media->save();
    $this->assertSame(1024, $media->thumbnail->width);
    $this->assertSame(768, $media->thumbnail->height);

    // Enable queued thumbnails and make sure that the entity gets the default     // thumbnail initially.     \Drupal::state()->set('media_source_test_definition', []);
    \Drupal::state()->set('media_source_test_attributes', [
      'thumbnail_uri' => ['value' => 'public://thumbnail1.jpg'],
    ]);
    $this->testMediaType->setQueueThumbnailDownloadsStatus(TRUE)->save();
    $media = Media::create([
      'bundle' => $this->testMediaType->id(),
      'name' => 'Mr. Jones',
      'field_media_test' => 'some_value',
    ]);
    $this->assertSame('public://thumbnail1.jpg', $media->getSource()->getMetadata($media, 'thumbnail_uri'), 'Value of the metadata attribute is not correct.');
    $media->save();
    $this->assertSame('public://media-icons/generic/generic.png', $media->thumbnail->entity->getFileUri(), 'Default thumbnail was not set initially.');
    $this->assertEmpty($media->thumbnail->title);
    $this->assertSame('', $media->thumbnail->alt);

    

  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->setValue('field_map', array_filter(
      $form_state->getValue('field_map', []),
      function D$item) {
        return $item != MediaSourceInterface::METADATA_FIELD_EMPTY;
      }
    ));

    parent::submitForm($form$form_state);

    $this->entity->setQueueThumbnailDownloadsStatus((bool) $form_state->getValue(['options', 'queue_thumbnail_downloads']))
      ->setStatus((bool) $form_state->getValue(['options', 'status']))
      ->setNewRevision((bool) $form_state->getValue(['options', 'new_revision']));

    if (isset($form['source_dependent']['source_configuration'])) {
      // Let the selected plugin save its settings.       $this->entity->getSource()->submitConfigurationForm($form['source_dependent']['source_configuration']$this->getSourceSubFormState($form$form_state));
    }
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.