Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OEL-739: Text with feature media video variants #109

Merged
merged 8 commits into from
Nov 16, 2021
Merged

OEL-739: Text with feature media video variants #109

merged 8 commits into from
Nov 16, 2021

Conversation

escuriola
Copy link
Contributor

@@ -72,30 +75,19 @@ function oe_bootstrap_theme_preprocess_paragraph__oe_text_feature_media(array &$
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = $variables['paragraph'];

// Link field doesn't exist in oe_paragraphs <= 1.8.0, so ensure it exists.
if ($paragraph->hasField('field_oe_link') && !$paragraph->get('field_oe_link')->isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

link is not needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a problem with the cyclomatic complexity threshold and I had to remove as many "if" as possible. Link already comes in content so for this reason I don't need to add to variables

includes/paragraphs.inc Outdated Show resolved Hide resolved
includes/paragraphs.inc Outdated Show resolved Hide resolved
includes/paragraphs.inc Outdated Show resolved Hide resolved
includes/paragraphs.inc Outdated Show resolved Hide resolved
* @param Drupal\media\Entity\Media $media
* Media object.
* @param array $variables
* Drupal variables.
Copy link
Contributor

Choose a reason for hiding this comment

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

In other places is 'The render array'. Change it so is consistent everywhere, please.

}

/**
* Set the image data if media is an image.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Set the image data if media is an image.
* Sets the image data if the media is an image.

* @param bool $is_image
* Flag to determine if is an image or not.
* @param array $variables
* Drupal variables.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as per the previous comment.

* @return array
* Updated variables.
*/
function set_ratio(Media $media, array &$variables, CacheableMetadata $cacheability): array {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, rename it to something like set_video_iframe_ratio to make it more explicit.

}

$thumbnail = $media->get('thumbnail')->first();
$variables['image'] = ImageValueObject::fromStyledImageItem($thumbnail, 'oe_bootstrap_theme_medium_no_crop');
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't it be like date in the List Item? This would mean to get the Image style not fixed as here but to get the 'configurable' image style set at the Thumbnail field in the Manage display in http://localhost:8080/build/admin/structure/media/manage/remote_video/display

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure of this. I'm using here the oe_theme way, maybe another way is possible, we can check this together.

$ratio = $media->get('oe_media_iframe_ratio')->value;
$variables['ratio'] = str_replace('_', 'x', $ratio);
$cacheability->applyTo($variables);
return $variables;
Copy link
Contributor

Choose a reason for hiding this comment

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

If setting values per reference, is necessary to return this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is needed because of the sign of the method:

function set_video_iframe_ratio(Media $media, array &$variables, CacheableMetadata $cacheability): array {

is waiting an array as the output of the method. So the return is needed for this reason.

@@ -14,15 +14,19 @@
'#alt': image.alt,
} %}
{% endif %}
{% if content.field_oe_text_long['#items'] %}
Copy link
Contributor

Choose a reason for hiding this comment

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

The default value is set at the paragraph.inc as FALSE, can't it be all set in same place (twig or paragraph.inc)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No because this settings deppends of the full text field is fulfilled or not, so by default is false but if the full text field has some content, the settings must be true.

* Test 'text with featured media' paragraph rendering.
*/
public function testFeaturedMedia(): void {
$image_file = file_save_data(file_get_contents(drupal_get_path('theme', 'oe_bootstrap_theme') . '/tests/fixtures/example_1.jpeg'), 'public://example_1_en.jpeg');
Copy link
Contributor

Choose a reason for hiding this comment

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

If the file is not needed as _en, use same name as source file.

@drishu drishu merged commit f685762 into 1.x Nov 16, 2021
@drishu drishu deleted the OEL-739 branch November 16, 2021 07:39
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.

None yet

4 participants