X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fmedia_entity_document%2Fsrc%2FPlugin%2FMediaEntity%2FType%2FDocument.php;fp=web%2Fmodules%2Fcontrib%2Fmedia_entity_document%2Fsrc%2FPlugin%2FMediaEntity%2FType%2FDocument.php;h=0000000000000000000000000000000000000000;hp=196117d2d3c7b3d94ab5cb700109abb54579201b;hb=419f97be044f1aebd0713921ee604841127e9e84;hpb=052617e40b525f8b817d84c29b1c04951f427069 diff --git a/web/modules/contrib/media_entity_document/src/Plugin/MediaEntity/Type/Document.php b/web/modules/contrib/media_entity_document/src/Plugin/MediaEntity/Type/Document.php deleted file mode 100644 index 196117d2d..000000000 --- a/web/modules/contrib/media_entity_document/src/Plugin/MediaEntity/Type/Document.php +++ /dev/null @@ -1,100 +0,0 @@ - t('File MIME'), - 'size' => t('Size'), - ]; - } - - /** - * {@inheritdoc} - */ - public function getField(MediaInterface $media, $name) { - $source_field = $this->configuration['source_field']; - $property_name = $media->{$source_field}->first()->mainPropertyName(); - - // Get the file document. - /** @var \Drupal\file\FileInterface $file */ - $file = $this->entityTypeManager->getStorage('file')->load($media->{$source_field}->first()->{$property_name}); - - // Return the field. - switch ($name) { - case 'mime': - return !$file->filemime->isEmpty() ? $file->getMimeType() : FALSE; - - case 'size': - $size = $file->getSize(); - return $size ? $size : FALSE; - } - - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - /** @var \Drupal\media_entity\MediaBundleInterface $bundle */ - $bundle = $form_state->getFormObject()->getEntity(); - $options = []; - $allowed_field_types = ['file']; - foreach ($this->entityFieldManager->getFieldDefinitions('media', $bundle->id()) as $field_name => $field) { - if (in_array($field->getType(), $allowed_field_types) && !$field->getFieldStorageDefinition()->isBaseField()) { - $options[$field_name] = $field->getLabel(); - } - } - - $form['source_field'] = [ - '#type' => 'select', - '#title' => t('Field with source information'), - '#description' => t('Field on media entity that stores Document file. You can create a bundle without selecting a value for this dropdown initially. This dropdown can be populated after adding fields to the bundle.'), - '#default_value' => empty($this->configuration['source_field']) ? NULL : $this->configuration['source_field'], - '#options' => $options, - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function thumbnail(MediaInterface $media) { - $source_field = $this->configuration['source_field']; - /** @var \Drupal\file\FileInterface $file */ - $file = $this->entityTypeManager->getStorage('file')->load($media->{$source_field}->target_id); - $mimetype = $file->getMimeType(); - $mimetype = explode('/', $mimetype); - $thumbnail = $this->config->get('icon_base') . "/{$mimetype[0]}-{$mimetype[1]}.png"; - - if (!is_file($thumbnail)) { - $thumbnail = $this->config->get('icon_base') . "/{$mimetype[1]}.png"; - - if (!is_file($thumbnail)) { - $thumbnail = $this->config->get('icon_base') . '/document.png'; - } - } - - return $thumbnail; - } - -}