diff --git a/composer.json b/composer.json index a0d2881d809034737271d44d94f186161723cb63..7db00e6f53ecc69d1144421a849b5679778c2ac8 100644 --- a/composer.json +++ b/composer.json @@ -123,7 +123,7 @@ "drupal/field_group": "3.1", "drupal/field_permissions": "1.1", "drupal/file_browser": "1.1", - "drupal/focal_point": "1.4", + "drupal/focal_point": "1.5", "drupal/geolocation": "1.10", "drupal/google_analytics": "2.5", "drupal/google_tag": "1.4", @@ -171,7 +171,7 @@ "drupal/svg_image": "1.14", "drupal/token": "1.7", "drupal/twig_tweak": "2.6", - "drupal/twitter_block": "3.0-alpha0", + "drupal/twitter_block": "3.0-alpha1", "drupal/userprotect": "1.1", "drupal/video_embed_field": "2.4", "drupal/view_unpublished": "1.0", diff --git a/composer.lock b/composer.lock index bfb94d657bef8648e880ce72a38b1140dda4c0dc..4cb02a2e2e03a4cdfd0b8f6477c251740f9a2fe3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "07b29dedae9eb37d26c05a4caadb8ea1", + "content-hash": "3a0a689eb38e0df625ca5642da5bcf83", "packages": [ { "name": "alchemy/zippy", @@ -4975,21 +4975,21 @@ }, { "name": "drupal/focal_point", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/focal_point.git", - "reference": "8.x-1.4" + "reference": "8.x-1.5" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/focal_point-8.x-1.4.zip", - "reference": "8.x-1.4", - "shasum": "8e377f61d0f590f7f89663ea3e841e56a3c14f5c" + "url": "https://ftp.drupal.org/files/projects/focal_point-8.x-1.5.zip", + "reference": "8.x-1.5", + "shasum": "41198e9220788c3b7d3146b10e5dfd6c73cd4784" }, "require": { - "drupal/core": "^8 || ^9", - "drupal/crop": "*" + "drupal/core": "^8.8 || ^9", + "drupal/crop": "^1.0 || ^2.0" }, "require-dev": { "drupal/crop": "*" @@ -4997,8 +4997,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-1.4", - "datestamp": "1586396577", + "version": "8.x-1.5", + "datestamp": "1598663903", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -5011,14 +5011,17 @@ ], "authors": [ { - "name": "bleen", - "homepage": "https://www.drupal.org/user/77375" + "name": "Alexander Ross (bleen)", + "homepage": "https://www.drupal.org/u/bleen", + "role": "Maintainer" } ], - "description": "Allows users to specify the focal point of an image for use during cropping.", - "homepage": "https://www.drupal.org/project/focal_point", + "description": "Focal Point allows content creators to mark the most important part of an image for easier cropping.", + "homepage": "https://drupal.org/project/focal_point", "support": { - "source": "https://git.drupalcode.org/project/focal_point" + "source": "https://cgit.drupalcode.org/focal_point", + "issues": "https://drupal.org/project/issues/focal_point", + "irc": "irc://irc.freenode.org/drupal-contribute" } }, { @@ -7822,29 +7825,26 @@ }, { "name": "drupal/twitter_block", - "version": "3.0.0-alpha0", + "version": "3.0.0-alpha1", "source": { "type": "git", "url": "https://git.drupalcode.org/project/twitter_block.git", - "reference": "8.x-3.0-alpha0" + "reference": "8.x-3.0-alpha1" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/twitter_block-8.x-3.0-alpha0.zip", - "reference": "8.x-3.0-alpha0", - "shasum": "f959bec1332f2bd45e813eefa3b982df4eb129bb" + "url": "https://ftp.drupal.org/files/projects/twitter_block-8.x-3.0-alpha1.zip", + "reference": "8.x-3.0-alpha1", + "shasum": "1ca5c6e30cda07b633273916bc0c3206e3928d81" }, "require": { - "drupal/core": "*" + "drupal/core": "^8.8 || ^9" }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-3.x": "3.x-dev" - }, "drupal": { - "version": "8.x-3.0-alpha0", - "datestamp": "1489574283", + "version": "8.x-3.0-alpha1", + "datestamp": "1603037906", "security-coverage": { "status": "not-covered", "message": "Alpha releases are not covered by Drupal security advisories." @@ -7880,7 +7880,7 @@ "description": "Provides configurable blocks for a Twitter feed.", "homepage": "http://drupal.org/project/twitter_block", "support": { - "source": "http://cgit.drupalcode.org/twitter_block" + "source": "https://git.drupalcode.org/project/twitter_block" } }, { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 261f46018388a052214a8281060dd8598268b173..13e011b2562509e40dfc1d216539780e446aa912 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -5123,22 +5123,22 @@ }, { "name": "drupal/focal_point", - "version": "1.4.0", - "version_normalized": "1.4.0.0", + "version": "1.5.0", + "version_normalized": "1.5.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/focal_point.git", - "reference": "8.x-1.4" + "reference": "8.x-1.5" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/focal_point-8.x-1.4.zip", - "reference": "8.x-1.4", - "shasum": "8e377f61d0f590f7f89663ea3e841e56a3c14f5c" + "url": "https://ftp.drupal.org/files/projects/focal_point-8.x-1.5.zip", + "reference": "8.x-1.5", + "shasum": "41198e9220788c3b7d3146b10e5dfd6c73cd4784" }, "require": { - "drupal/core": "^8 || ^9", - "drupal/crop": "*" + "drupal/core": "^8.8 || ^9", + "drupal/crop": "^1.0 || ^2.0" }, "require-dev": { "drupal/crop": "*" @@ -5146,8 +5146,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-1.4", - "datestamp": "1586396577", + "version": "8.x-1.5", + "datestamp": "1598663903", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -5161,14 +5161,17 @@ ], "authors": [ { - "name": "bleen", - "homepage": "https://www.drupal.org/user/77375" + "name": "Alexander Ross (bleen)", + "homepage": "https://www.drupal.org/u/bleen", + "role": "Maintainer" } ], - "description": "Allows users to specify the focal point of an image for use during cropping.", - "homepage": "https://www.drupal.org/project/focal_point", + "description": "Focal Point allows content creators to mark the most important part of an image for easier cropping.", + "homepage": "https://drupal.org/project/focal_point", "support": { - "source": "https://git.drupalcode.org/project/focal_point" + "source": "https://cgit.drupalcode.org/focal_point", + "issues": "https://drupal.org/project/issues/focal_point", + "irc": "irc://irc.freenode.org/drupal-contribute" } }, { @@ -8065,30 +8068,27 @@ }, { "name": "drupal/twitter_block", - "version": "3.0.0-alpha0", - "version_normalized": "3.0.0.0-alpha", + "version": "3.0.0-alpha1", + "version_normalized": "3.0.0.0-alpha1", "source": { "type": "git", "url": "https://git.drupalcode.org/project/twitter_block.git", - "reference": "8.x-3.0-alpha0" + "reference": "8.x-3.0-alpha1" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/twitter_block-8.x-3.0-alpha0.zip", - "reference": "8.x-3.0-alpha0", - "shasum": "f959bec1332f2bd45e813eefa3b982df4eb129bb" + "url": "https://ftp.drupal.org/files/projects/twitter_block-8.x-3.0-alpha1.zip", + "reference": "8.x-3.0-alpha1", + "shasum": "1ca5c6e30cda07b633273916bc0c3206e3928d81" }, "require": { - "drupal/core": "*" + "drupal/core": "^8.8 || ^9" }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-3.x": "3.x-dev" - }, "drupal": { - "version": "8.x-3.0-alpha0", - "datestamp": "1489574283", + "version": "8.x-3.0-alpha1", + "datestamp": "1603037906", "security-coverage": { "status": "not-covered", "message": "Alpha releases are not covered by Drupal security advisories." @@ -8125,7 +8125,7 @@ "description": "Provides configurable blocks for a Twitter feed.", "homepage": "http://drupal.org/project/twitter_block", "support": { - "source": "http://cgit.drupalcode.org/twitter_block" + "source": "https://git.drupalcode.org/project/twitter_block" } }, { diff --git a/web/modules/focal_point/composer.json b/web/modules/focal_point/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..ce849489d938fd80882778aa66da952f344a41ff --- /dev/null +++ b/web/modules/focal_point/composer.json @@ -0,0 +1,29 @@ +{ + "name": "drupal/focal_point", + "description": "Focal Point allows content creators to mark the most important part of an image for easier cropping.", + "type": "drupal-module", + "homepage": "https://drupal.org/project/focal_point", + "authors": [ + { + "name": "Alexander Ross (bleen)", + "homepage": "https://www.drupal.org/u/bleen", + "role": "Maintainer" + } + ], + "support": { + "issues": "https://drupal.org/project/issues/focal_point", + "irc": "irc://irc.freenode.org/drupal-contribute", + "source": "https://cgit.drupalcode.org/focal_point" + }, + "license": "GPL-2.0-or-later", + "minimum-stability": "dev", + "repositories": [ + { + "type": "composer", + "url": "https://packages.drupal.org/8" + } + ], + "require": { + "drupal/crop": "^1.0 || ^2.0" + } +} diff --git a/web/modules/focal_point/focal_point.info.yml b/web/modules/focal_point/focal_point.info.yml index 032ec598ad2111d73a8d114ea0d4ac50c322772b..490faaae7ba08472eaf9732a80521dde824831df 100644 --- a/web/modules/focal_point/focal_point.info.yml +++ b/web/modules/focal_point/focal_point.info.yml @@ -1,8 +1,7 @@ name: Focal Point type: module description: Allows users to specify the focal point of an image for use during cropping. -core: 8.x -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8.8 || ^9 package: Media test_dependencies: - crop:crop @@ -10,7 +9,7 @@ dependencies: - drupal:image - crop:crop -# Information added by Drupal.org packaging script on 2020-04-09 -version: '8.x-1.4' +# Information added by Drupal.org packaging script on 2020-08-29 +version: '8.x-1.5' project: 'focal_point' -datestamp: 1586396579 +datestamp: 1598663906 diff --git a/web/modules/focal_point/focal_point.module b/web/modules/focal_point/focal_point.module index 19307a546a577702b86efdc268d503895bdff654..b10bf789868bfa97606ead42ad950d20fe60a6bd 100644 --- a/web/modules/focal_point/focal_point.module +++ b/web/modules/focal_point/focal_point.module @@ -8,6 +8,7 @@ * @todo add test drive functionality? */ +use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Form\FormStateInterface; @@ -109,3 +110,54 @@ function focal_point_entity_update(EntityInterface $entity) { function focal_point_imce_supported_widgets_alter(array &$widgets) { $widgets[] = 'image_focal_point'; } + +/** + * Implements hook_form_FORM_ID_alter(). + */ +function focal_point_form_media_library_add_form_upload_alter(array &$form, FormStateInterface $form_state) { + // Get any media items that are in the process of being added. + // @see \Drupal\media_library\Form\AddFormBase::getAddedMediaItems(). + $media = $form_state->get('media') ?: []; + /** @var \Drupal\media\MediaInterface $item */ + foreach ($media as $delta => $item) { + $element = &$form['media'][$delta]['fields']; + // As a kindness to alter hooks like this one, Media Library includes the + // name of the source field in the form structure. + // @see \Drupal\media_library\Form\AddFormBase::buildEntityFormElement() + $source_field = $element['#source_field_name']; + // If the source field is configured to use Focal Point, add a #process + // callback which replaces the static preview thumbnail with the Focal Point + // widget. + $component = \Drupal::service('entity_display.repository') + ->getFormDisplay('media', $item->bundle(), 'media_library') + ->getComponent($source_field); + if ($component && $component['type'] === 'image_focal_point' && isset($element[$source_field])) { + $element[$source_field]['widget'][0]['#process'][] = '_focal_point_replace_media_library_preview'; + } + } +} + +/** + * Process callback for the preview image of a new item in the media library. + */ +function _focal_point_replace_media_library_preview(array $element, FormStateInterface $form_state, array &$form) { + // We expect $element to be an image field widget with Focal Point enabled. + if (!empty($element['preview'])) { + // Temporarily override the preview access, which is normally set to FALSE + // by the media library, in favor of its own static preview thumbnail. In + // this case, though, Focal Point is using the preview to provide its + // widget, so we want to be sure that's visible. + $preview_access = $element['preview']['#access']; + $element['preview']['#access'] = TRUE; + // We expect the array parents to be something like + // ['media', $delta, 'fields', $source_field, 'widget', 0]. Here, we + // transform that to target the static preview thumbnail, which we expect to + // be at ['media', $delta, 'preview', 'thumbnail']. + $target = $element['#array_parents']; + array_splice($target, -4, count($target), ['preview', 'thumbnail']); + NestedArray::setValue($form, $target, $element['preview']); + // We've done what we needed to do, so restore the original preview access. + $element['preview']['#access'] = $preview_access; + } + return $element; +} diff --git a/web/modules/focal_point/js/focal_point.js b/web/modules/focal_point/js/focal_point.js index 22aa739b60c6d69a81d3851642d4b73126d0ca74..3ca457d9dd9d50da766d7164c8d664200eea7bab 100644 --- a/web/modules/focal_point/js/focal_point.js +++ b/web/modules/focal_point/js/focal_point.js @@ -3,15 +3,15 @@ * Javascript functionality for the focal point widget. */ -(function($, Drupal) { +(function ($, Drupal) { 'use strict'; /** * Focal Point indicator. */ Drupal.behaviors.focalPointIndicator = { - attach: function(context) { - $(".focal-point", context).once('focal-point-hide-field').each(function() { + attach: function (context) { + $(".focal-point", context).once('focal-point-hide-field').each(function () { var $wrapper = $(this).closest('.focal-point-wrapper'); // Add the "visually-hidden" class unless the focal point offset field // has an error. This will show the field for everyone when there is an @@ -28,7 +28,7 @@ } }); - $(".focal-point-indicator", context).once('focal-point-indicator').each(function() { + $(".focal-point-indicator", context).once('focal-point-indicator').each(function () { // Set some variables for the different pieces at play. var $indicator = $(this); var $img = $(this).siblings('img'); @@ -41,11 +41,13 @@ // image is loaded before moving the crosshair. See http://goo.gl/B02vFO // The setTimeout was added to ensure the focal point is set properly on // modal windows. See http://goo.gl/s73ge. - setTimeout(function() { - $img.one('load', function(){ + setTimeout(function () { + $img.one('load', function () { fp.setIndicator(); - }).each(function() { - if (this.complete) $(this).trigger('load'); + }).each(function () { + if (this.complete) { + $(this).trigger('load'); + } }); }, 0); @@ -66,7 +68,7 @@ * @param $previewLink object * The previewLink jQuery object. */ - Drupal.FocalPoint = function($indicator, $img, $field, $previewLink) { + Drupal.FocalPoint = function ($indicator, $img, $field, $previewLink) { var self = this; this.$indicator = $indicator; @@ -78,7 +80,7 @@ // appropriate field when it is moved by the user. this.$indicator.draggable({ containment: self.$img, - stop: function() { + stop: function () { var imgOffset = self.$img.offset(); var focalPointOffset = self.$indicator.offset(); @@ -91,20 +93,20 @@ // Allow users to double-click the indicator to reveal the focal point form // element. - this.$indicator.on('dblclick', function() { + this.$indicator.on('dblclick', function () { self.$field.closest('.focal-point-wrapper').toggleClass('visually-hidden'); }); // Allow users to click on the image preview in order to set the focal_point // and set a cursor. - this.$img.on('click', function(event) { + this.$img.on('click', function (event) { self.set(event.offsetX, event.offsetY); }); this.$img.css('cursor', 'crosshair'); // Add a change event to the focal point field so it will properly update // the indicator position and preview link. - this.$field.on('change', function() { + this.$field.on('change', function () { $(document).trigger('drupalFocalPointSet', { $focalPoint: self }); }); @@ -121,7 +123,7 @@ * @param offsetY int * Top offset in pixels. */ - Drupal.FocalPoint.prototype.set = function(offsetX, offsetY) { + Drupal.FocalPoint.prototype.set = function (offsetX, offsetY) { var focalPoint = this.calculate(offsetX, offsetY); this.$field.val(focalPoint.x + ',' + focalPoint.y).trigger('change'); @@ -131,7 +133,7 @@ /** * Change the position of the focal point indicator. This may not work in IE7. */ - Drupal.FocalPoint.prototype.setIndicator = function() { + Drupal.FocalPoint.prototype.setIndicator = function () { var coordinates = this.$field.val() !== '' && this.$field.val() !== undefined ? this.$field.val().split(',') : [50,50]; var left = Math.min(this.$img.width(), (parseInt(coordinates[0], 10) / 100) * this.$img.width()); @@ -152,7 +154,7 @@ * * @returns object */ - Drupal.FocalPoint.prototype.calculate = function(offsetX, offsetY) { + Drupal.FocalPoint.prototype.calculate = function (offsetX, offsetY) { var focalPoint = {}; focalPoint.x = this.round(100 * offsetX / this.$img.width(), 0, 100); focalPoint.y = this.round(100 * offsetY / this.$img.height(), 0, 100); @@ -172,7 +174,7 @@ * * @returns int */ - Drupal.FocalPoint.prototype.round = function(value, min, max){ + Drupal.FocalPoint.prototype.round = function (value, min, max) { var roundedVal = Math.max(Math.round(value), min); roundedVal = Math.min(roundedVal, max); @@ -200,7 +202,7 @@ } // Update the ajax binding to reflect the new preview link href value. - Drupal.ajax.instances.forEach(function(instance, index) { + Drupal.ajax.instances.forEach(function (instance, index) { if (instance && $(instance.element).data('selector') === dataSelector) { var href = $(instance.selector).attr('href'); Drupal.ajax.instances[index].url = href; diff --git a/web/modules/focal_point/js/focal_point_preview.js b/web/modules/focal_point/js/focal_point_preview.js index a12c8acbeee1c1e1f91a6f6747f47cc32c542e10..7d18e4230216305f1a8ce8a020e5e6705df087d0 100644 --- a/web/modules/focal_point/js/focal_point_preview.js +++ b/web/modules/focal_point/js/focal_point_preview.js @@ -3,14 +3,14 @@ * Javascript functionality for the focal point preview page. */ -(function($, Drupal) { +(function ($, Drupal) { 'use strict'; /** * Focal Point preview. */ Drupal.behaviors.focalPointPreview = { - attach: function(context, settings) { + attach: function (context, settings) { var $focalPointDerivativePreviews = $(".focal-point-derivative-preview"); var $focalPointImagePreview = $("#focal-point-preview-image"); @@ -21,7 +21,7 @@ // Add a click event to each derivative preview. $focalPointDerivativePreviews.each(function () { - $(this).click(function(event) { + $(this).click(function (event) { // Remove any image style classes added by active previews. $(".focal-point-derivative-preview.active").each(function () { $focalPointImagePreview.removeClass($(this).data('image-style')) @@ -48,10 +48,10 @@ }); // Add some window events for reverting to the original image. - $(window).click(function(event) { + $(window).click(function (event) { resetPreview(); }); - $(window).keyup(function(event) { + $(window).keyup(function (event) { // Check if the esc key was pressed. if (event.keyCode === 27) { resetPreview(); diff --git a/web/modules/focal_point/src/Controller/FocalPointPreviewController.php b/web/modules/focal_point/src/Controller/FocalPointPreviewController.php index 6ef2c5c53b0ec810af8274166247fa489194d66f..a7ef76fd9cfe5822604a780250b1f9b99537b9bb 100644 --- a/web/modules/focal_point/src/Controller/FocalPointPreviewController.php +++ b/web/modules/focal_point/src/Controller/FocalPointPreviewController.php @@ -4,9 +4,9 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\focal_point\Plugin\Field\FieldWidget\FocalPointImageWidget; -use Drupal\image\Entity\ImageStyle; use Drupal\file\Entity\File; use Drupal\Core\Session\AccountInterface; +use Drupal\image\ImageStyleInterface; use Symfony\Component\Validator\Exception\InvalidArgumentException; use Drupal\Core\Access\AccessResult; use Drupal\Core\Entity\EntityStorageInterface; @@ -16,7 +16,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Image\ImageFactory; use Symfony\Component\HttpFoundation\RequestStack; -use Drupal\Core\Render\RendererInterface; /** * Class FocalPointPreviewController. @@ -46,13 +45,6 @@ class FocalPointPreviewController extends ControllerBase { */ protected $fileStorage; - /** - * The renderer service. - * - * @var Drupal\Core\Render\RendererInterface - */ - protected $renderer; - /** * {@inheritdoc} * @@ -61,11 +53,10 @@ class FocalPointPreviewController extends ControllerBase { * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request parameter. */ - public function __construct(ImageFactory $image_factory, RequestStack $request_stack, RendererInterface $renderer) { + public function __construct(ImageFactory $image_factory, RequestStack $request_stack) { $this->imageFactory = $image_factory; $this->request = $request_stack->getCurrentRequest(); $this->fileStorage = $this->entityTypeManager()->getStorage('file'); - $this->renderer = $renderer; } /** @@ -74,8 +65,7 @@ public function __construct(ImageFactory $image_factory, RequestStack $request_s public static function create(ContainerInterface $container) { return new static( $container->get('image.factory'), - $container->get('request_stack'), - $container->get('renderer') + $container->get('request_stack') ); } @@ -151,15 +141,13 @@ public function content($fid, $focal_point_value) { '#derivative_image_note' => $derivative_image_note, ]; - $html = $this->renderer->renderPlain($output); - $options = [ 'dialogClass' => 'popup-dialog-class', 'width' => '80%', ]; $response = new AjaxResponse(); $response->addCommand( - new OpenModalDialogCommand($this->t('Images preview'), $html, $options) + new OpenModalDialogCommand($this->t('Images preview'), $output, $options) ); return $response; @@ -244,7 +232,7 @@ public function getFocalPointImageStyles() { /** * Create the URL for a preview image including a query parameter. * - * @param \Drupal\image\Entity\ImageStyle $style + * @param \Drupal\image\ImageStyleInterface $style * The image style being previewed. * @param \Drupal\file\Entity\File $image * The image being previewed. @@ -255,7 +243,7 @@ public function getFocalPointImageStyles() { * @return \Drupal\Core\GeneratedUrl|string * The URL of the preview image. */ - protected function buildUrl(ImageStyle $style, File $image, $focal_point_value) { + protected function buildUrl(ImageStyleInterface $style, File $image, $focal_point_value) { $url = $style->buildUrl($image->getFileUri()); $url .= (strpos($url, '?') !== FALSE ? '&' : '?') . 'focal_point_preview_value=' . $focal_point_value; diff --git a/web/modules/focal_point/src/FocalPointManager.php b/web/modules/focal_point/src/FocalPointManager.php index b6e5b67f732383949290f3c3b21e25df8c8b8103..84ec7d3b098e8615c6016c034ca1602393f3bd54 100644 --- a/web/modules/focal_point/src/FocalPointManager.php +++ b/web/modules/focal_point/src/FocalPointManager.php @@ -60,8 +60,8 @@ public function relativeToAbsolute($x, $y, $width, $height) { */ public function absoluteToRelative($x, $y, $width, $height) { return [ - 'x' => (int) round($x / $width * 100), - 'y' => (int) round($y / $height * 100), + 'x' => $width ? (int) round($x / $width * 100) : 0, + 'y' => $height ? (int) round($y / $height * 100) : 0, ]; } diff --git a/web/modules/focal_point/tests/src/Functional/FocalPointWidgetTest.php b/web/modules/focal_point/tests/src/Functional/FocalPointWidgetTest.php index 9573e9793381da889c4d3ecdcf34a466ac77bd76..64e5eb74b1acc79fa3404338d93d69135211347b 100644 --- a/web/modules/focal_point/tests/src/Functional/FocalPointWidgetTest.php +++ b/web/modules/focal_point/tests/src/Functional/FocalPointWidgetTest.php @@ -42,9 +42,11 @@ public function setUp() { $type->save(); $this->container->get('router.builder')->rebuild(); - } + /** + * {@inheritDoc} + */ public function testResave() { $field_name = strtolower($this->randomMachineName()); diff --git a/web/modules/focal_point/tests/src/FunctionalJavascript/MediaLibraryIntegrationTest.php b/web/modules/focal_point/tests/src/FunctionalJavascript/MediaLibraryIntegrationTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9ba048ef023601d8b85f87f92264e5fef3c96da5 --- /dev/null +++ b/web/modules/focal_point/tests/src/FunctionalJavascript/MediaLibraryIntegrationTest.php @@ -0,0 +1,127 @@ +<?php + +namespace Drupal\Tests\focal_point\FunctionalJavascript; + +use Behat\Mink\Element\DocumentElement; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; +use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\Tests\media\Traits\MediaTypeCreationTrait; +use Drupal\Tests\TestFileCreationTrait; + +/** + * Tests Focal Point's integration with Media Library. + * + * @group focal_point + */ +class MediaLibraryIntegrationTest extends WebDriverTestBase { + + use MediaTypeCreationTrait; + use TestFileCreationTrait; + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'node', + 'media_library', + 'focal_point', + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->drupalCreateContentType([ + 'type' => 'article', + ]); + $this->createMediaType('image', [ + 'id' => 'image', + ]); + + $field_storage = FieldStorageConfig::create([ + 'entity_type' => 'node', + 'field_name' => 'field_image', + 'type' => 'entity_reference', + 'settings' => [ + 'target_type' => 'media', + ], + ]); + $field_storage->save(); + + FieldConfig::create([ + 'field_storage' => $field_storage, + 'bundle' => 'article', + 'label' => 'Image', + 'settings' => [ + 'handler_settings' => [ + 'target_bundles' => [ + 'image' => 'image', + ], + ], + ], + ])->save(); + + // Ensure that the media type is using Focal Point in its media library + // form display. + /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ + $display_repository = $this->container->get('entity_display.repository'); + $display_repository->getFormDisplay('media', 'image', 'media_library') + ->setComponent('field_media_image', [ + 'type' => 'image_focal_point', + 'settings' => [ + 'preview_image_style' => 'media_library', + ], + ]) + ->save(); + // Ensure that the media field on the Article content type is using the + // media library. + $display_repository->getFormDisplay('node', 'article') + ->setComponent('field_image', [ + 'type' => 'media_library_widget', + ]) + ->save(); + + $user = $this->drupalCreateUser([ + 'create article content', + 'create media', + 'access media overview', + ]); + $this->drupalLogin($user); + } + + /** + * Tests Focal Point integration with the media library. + */ + public function testFocalPointMediaField() { + $page = $this->getSession()->getPage(); + $assert_session = $this->assertSession(); + + $files = $this->getTestFiles('image'); + $path = $this->container->get('file_system')->realpath($files[0]->uri); + $this->assertNotEmpty($path); + + // Upload an image and ensure that a single Focal Point widget shows up. + $this->drupalGet('/node/add/article'); + $page->pressButton('Add media'); + $file_field = $assert_session->waitForField('Add file'); + $this->assertNotEmpty($file_field); + $file_field->attachFile($path); + + $widget_exists = $this->getSession() + ->getPage() + ->waitFor(10, function (DocumentElement $page) { + $elements = $page->findAll('css', '[data-media-library-added-delta] .focal-point-indicator'); + return count($elements) === 1; + }); + $this->assertTrue($widget_exists); + } + +} diff --git a/web/modules/twitter_block/src/Plugin/Block/TwitterBlock.php b/web/modules/twitter_block/src/Plugin/Block/TwitterBlock.php index b6ad5c29ef96a8aeede5b6c756b7e38119727f17..9ca2fe1eec127bfd7b41a402c7e764466fc4d4ed 100644 --- a/web/modules/twitter_block/src/Plugin/Block/TwitterBlock.php +++ b/web/modules/twitter_block/src/Plugin/Block/TwitterBlock.php @@ -95,13 +95,16 @@ public function blockForm($form, FormStateInterface $form_state) { '#type' => 'select', '#title' => $this->t('Tweet limit'), '#default_value' => $config['tweet_limit'], - '#options' => ['' => $this->t('Auto')] + [array_combine(range(1, 20), range(1, 20))], + '#options' => ['' => $this->t('Auto')], '#description' => $this->t('Fix the size of a timeline to a preset number of Tweets between 1 and 20. The timeline will render the specified number of Tweets from the timeline, expanding the height of the widget to display all Tweets without scrolling. Since the widget is of a fixed size, it will not poll for updates when using this option.'), ]; + $form['functionality']['tweet_limit']['#options'] += + array_combine(range(1, 20), range(1, 20)); + $form['size'] = [ '#type' => 'fieldset', '#title' => $this->t('Size'), diff --git a/web/modules/twitter_block/src/Tests/TwitterBlockTest.php b/web/modules/twitter_block/tests/src/Functional/TwitterBlockTest.php similarity index 72% rename from web/modules/twitter_block/src/Tests/TwitterBlockTest.php rename to web/modules/twitter_block/tests/src/Functional/TwitterBlockTest.php index 051e144e7d07f51b5b47600b73511eb3bb4aed74..9dd867e1dac362540d152d51bab0b10a7c3aa317 100644 --- a/web/modules/twitter_block/src/Tests/TwitterBlockTest.php +++ b/web/modules/twitter_block/tests/src/Functional/TwitterBlockTest.php @@ -1,15 +1,15 @@ <?php -namespace Drupal\twitter_block\Tests; +namespace Drupal\Tests\twitter_block\Functional; -use Drupal\simpletest\WebTestBase; +use Drupal\Tests\BrowserTestBase; /** * Tests if the twitter block is available. * * @group twitter_block */ -class TwitterBlockTest extends WebTestBase { +class TwitterBlockTest extends BrowserTestBase { /** * Modules to enable. @@ -21,13 +21,14 @@ class TwitterBlockTest extends WebTestBase { /** * {@inheritdoc} */ - protected function setUp() { + public function setUp() { parent::setUp(); - // Create and login user. - $admin_user = $this->drupalCreateUser(array( - 'administer blocks', 'administer site configuration', + + $admin_user = $this->drupalCreateUser([ + 'administer blocks', + 'administer site configuration', 'access administration pages', - )); + ]); $this->drupalLogin($admin_user); } @@ -41,17 +42,17 @@ public function testTwitterBlock() { foreach (['bartik', 'seven', 'stark'] as $theme) { $this->drupalGet('admin/structure/block/list/' . $theme); // Configure and save the block. - $this->drupalPlaceBlock('twitter_block', array( + $this->drupalPlaceBlock('twitter_block', [ 'username' => 'drupal', 'width' => 180, 'height' => 200, 'region' => 'content', 'theme' => $theme, - )); + ]); // Set the default theme and ensure the block is placed. $theme_settings->set('default', $theme)->save(); $this->drupalGet(''); - $this->assertText('Tweets by @drupal', 'Twitter block found'); + $this->assertSession()->pageTextContains('Tweets by @drupal', 'Twitter block found'); } } diff --git a/web/modules/twitter_block/twitter_block.info.yml b/web/modules/twitter_block/twitter_block.info.yml index 575c36921734e9b28001f0017cdd0afde31275e1..b6b3028206db85af4006ff1797343768e64505d1 100644 --- a/web/modules/twitter_block/twitter_block.info.yml +++ b/web/modules/twitter_block/twitter_block.info.yml @@ -1,12 +1,11 @@ name: Twitter Block type: module description: 'Provides configurable blocks for a Twitter feed.' -# core: 8.x +core_version_requirement: ^8.8 || ^9 dependencies: - - block + - drupal:block -# Information added by Drupal.org packaging script on 2017-03-15 -version: '8.x-3.0-alpha0' -core: '8.x' +# Information added by Drupal.org packaging script on 2020-10-18 +version: '8.x-3.0-alpha1' project: 'twitter_block' -datestamp: 1489574287 +datestamp: 1603037909 diff --git a/web/modules/twitter_block/twitter_block.libraries.yml b/web/modules/twitter_block/twitter_block.libraries.yml index 2db93af7764c63822701ae51401c152cccf081e3..ecf275575d4f0b6de34621cb47d8ac3bafc95ca5 100644 --- a/web/modules/twitter_block/twitter_block.libraries.yml +++ b/web/modules/twitter_block/twitter_block.libraries.yml @@ -1,3 +1,3 @@ widgets: js: - https://platform.twitter.com/widgets.js: { type: external } + //platform.twitter.com/widgets.js: { type: external, minified: true, attributes: { async: true } }