Skip to content

EWPP-253: Move media creation into trait.#124

Open
drishu wants to merge 3 commits intomasterfrom
EWPP-253
Open

EWPP-253: Move media creation into trait.#124
drishu wants to merge 3 commits intomasterfrom
EWPP-253

Conversation

@drishu
Copy link
Contributor

@drishu drishu commented Sep 17, 2020

EWPP-253

Description

Move media creation into trait.

Change log

  • Added: trait MediaCreationTrait
  • Changed: MediaContext
  • Fixed: getMediaEntityFromRef return type hint

'oe_media_image' => [
'target_id' => $file_id,
'alt' => $properties['alt'] ?? $properties['name'],
'title' => $properties['title'] ?? $properties['name'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please check createBlock() in build/core/modules/views/tests/src/Kernel/Plugin/BlockDependenciesTest.php. Might be it can be useful to organise code as there (look at the $settings) - it allows to provide wide range of variables even that we don't expect now.
Also would be nice to have ability to override media status.

@drishu drishu force-pushed the EWPP-253 branch 2 times, most recently from 3321c22 to ec39a1f Compare September 17, 2020 15:14
$settings += [
'name' => $this->getFileNameSuggestion($file),
'file_id' => FALSE,
'alt' => 'image',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be we can use $this->getFileNameSuggestion($file) for alt and title to make them more specific.

trait MediaCreationTrait {

/**
* Create a file entity from given file path.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... from the given file path.

* @return \Drupal\media\Entity\Media
* The media object.
*/
protected function createMediaDocument(FileInterface $file, array $settings = []): Media {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type hint should be MediaInterface.

* @param array $settings
* An associative array of settings for the media entity.
*
* @return \Drupal\media\Entity\Media
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MediaInterface

* @return \Drupal\media\Entity\Media
* The media object.
*/
protected function createMediaImage(FileInterface $file, array $settings = []): Media {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be MediaInterface

* @return \Drupal\media\Entity\Media
* The media object.
*/
protected function createMediaAvPortalPhoto(MediaAvPortalSourceInterface $media_source, array $settings = []): Media {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MediaInterface

* @return \Drupal\media\Entity\Media
* The media object.
*/
protected function createMediaRemoteVideo(array $settings = []): Media {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MediaInterface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants