Update to Drupal 8.1.5. For more information, see https://www.drupal.org/project/drupal/releases/8.1.5
This commit is contained in:
parent
13b6ca7cc2
commit
38ba7c357d
342 changed files with 7814 additions and 1534 deletions
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Post update functions for Responsive Image.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
|
||||
/**
|
||||
* @addtogroup updates-8.1.x
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Make responsive image formatters dependent on responsive image styles.
|
||||
*/
|
||||
function responsive_image_post_update_recreate_dependencies() {
|
||||
$displays = EntityViewDisplay::loadMultiple();
|
||||
array_walk($displays, function(EntityViewDisplayInterface $entity_view_display) {
|
||||
$old_dependencies = $entity_view_display->getDependencies();
|
||||
$new_dependencies = $entity_view_display->calculateDependencies()->getDependencies();
|
||||
if ($old_dependencies !== $new_dependencies) {
|
||||
$entity_view_display->save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup updates-8.1.x".
|
||||
*/
|
|
@ -10,6 +10,7 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase;
|
||||
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Utility\LinkGeneratorInterface;
|
||||
|
@ -247,4 +248,18 @@ class ResponsiveImageFormatter extends ImageFormatterBase implements ContainerFa
|
|||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
$dependencies = parent::calculateDependencies();
|
||||
$style_id = $this->getSetting('responsive_image_style');
|
||||
/** @var \Drupal\responsive_image\ResponsiveImageStyleInterface $style */
|
||||
if ($style_id && $style = ResponsiveImageStyle::load($style_id)) {
|
||||
// Add the responsive image style as dependency.
|
||||
$dependencies[$style->getConfigDependencyKey()][] = $style->getConfigDependencyName();
|
||||
}
|
||||
return $dependencies;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\responsive_image\Tests\Update;
|
||||
|
||||
use Drupal\Component\Serialization\Yaml;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests responsive image module updates.
|
||||
*
|
||||
* @group responsive_image
|
||||
*/
|
||||
class ResponsiveImageUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
/** @var \Drupal\Core\State\StateInterface $state */
|
||||
$state = $this->container->get('state');
|
||||
|
||||
// Enable responsive_image module without using the module installer to
|
||||
// avoid installation of configuration shipped in module.
|
||||
$system_module_files = $state->get('system.module.files', []);
|
||||
$system_module_files += ['responsive_image' => 'core/modules/responsive_image/responsive_image.info.yml'];
|
||||
$state->set('system.module.files', $system_module_files);
|
||||
$this->config('core.extension')->set('module.responsive_image', 0)->save();
|
||||
$this->container->get('module_handler')->addModule('responsive_image', 'core/modules/responsive_image');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests post-update responsive_image_post_update_dependency().
|
||||
*
|
||||
* @see responsive_image_post_update_dependency()
|
||||
*/
|
||||
public function testPostUpdateDependency() {
|
||||
// Installing the 'wide' responsive image style.
|
||||
$wide_image_style = Yaml::decode(file_get_contents(__DIR__ . '/../../../../../profiles/standard/config/optional/responsive_image.styles.wide.yml'));
|
||||
$this->config('responsive_image.styles.wide')->setData($wide_image_style)->save(TRUE);
|
||||
|
||||
// Change 'field_image' formatter to a responsive image formatter.
|
||||
$options = [
|
||||
'type' => 'responsive_image',
|
||||
'label' => 'hidden',
|
||||
'settings' => ['responsive_image_style' => 'wide', 'image_link' => ''],
|
||||
'third_party_settings' => [],
|
||||
];
|
||||
$display = $this->config('core.entity_view_display.node.article.default');
|
||||
$display->set('content.field_image', $options)->save(TRUE);
|
||||
|
||||
// Check that there's no dependency to 'responsive_image.styles.wide'.
|
||||
$dependencies = $display->get('dependencies.config') ?: [];
|
||||
$this->assertFalse(in_array('responsive_image.styles.wide', $dependencies));
|
||||
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
|
||||
$view_display = EntityViewDisplay::load('node.article.default');
|
||||
$dependencies = $view_display->getDependencies() + ['config' => []];
|
||||
// Check that post-update added a 'responsive_image.styles.wide' dependency.
|
||||
$this->assertTrue(in_array('responsive_image.styles.wide', $dependencies['config']));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\responsive_image\Kernel;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
|
||||
|
||||
/**
|
||||
* Tests the integration of responsive image with other components.
|
||||
*
|
||||
* @group responsive_image
|
||||
*/
|
||||
class ResponsiveImageIntegrationTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['responsive_image', 'field', 'image', 'file', 'entity_test', 'breakpoint', 'responsive_image_test_module'];
|
||||
|
||||
/**
|
||||
* Tests integration with entity view display.
|
||||
*/
|
||||
public function testEntityViewDisplayDependency() {
|
||||
// Create a responsive image style.
|
||||
ResponsiveImageStyle::create([
|
||||
'id' => 'foo',
|
||||
'label' => 'Foo',
|
||||
'breakpoint_group' => 'responsive_image_test_module',
|
||||
])->save();
|
||||
// Create an image field to be used with a responsive image formatter.
|
||||
FieldStorageConfig::create([
|
||||
'type' => 'image',
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'bar',
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
'field_name' => 'bar',
|
||||
])->save();
|
||||
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
|
||||
$display = EntityViewDisplay::create([
|
||||
'targetEntityType' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
'mode' => 'default',
|
||||
]);
|
||||
$display->setComponent('bar', [
|
||||
'type' => 'responsive_image',
|
||||
'label' => 'hidden',
|
||||
'settings' => ['responsive_image_style' => 'foo', 'image_link' => ''],
|
||||
'third_party_settings' => [],
|
||||
])->save();
|
||||
|
||||
// Check that the 'foo' field is on the display.
|
||||
$this->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
|
||||
$this->assertTrue($display->getComponent('bar'));
|
||||
$this->assertArrayNotHasKey('bar', $display->get('hidden'));
|
||||
|
||||
// Delete the responsive image style.
|
||||
ResponsiveImageStyle::load('foo')->delete();
|
||||
|
||||
// Check that the view display was not deleted.
|
||||
$this->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
|
||||
// Check that the 'foo' field was disabled.
|
||||
$this->assertNull($display->getComponent('bar'));
|
||||
$this->assertArrayHasKey('bar', $display->get('hidden'));
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue