Skip to content
Snippets Groups Projects
Verified Commit ffd37800 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3272969 by LOBsTerr, smustgrave, metasim, larowlan, Abhijith S,...

Issue #3272969 by LOBsTerr, smustgrave, metasim, larowlan, Abhijith S, Devashish Jangid, johnwebdev, vakulrai, tedbow, ranjith_kumar_k_u, nghai: Remove unique constraint on block content info field
parent 79cd4d36
No related branches found
No related tags found
29 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!4100Issue #3249600: Add support for PHP 8.1 Enums as allowed values for list_* data types,!3630Issue #2815301 by Chi, DanielVeza, kostyashupenko, smustgrave: Allow to create...,!3600Issue #3344629: Passing null to parameter #1 ($haystack) of type string is deprecated,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!957Added throwing of InvalidPluginDefinitionException from getDefinition().,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -35,3 +35,18 @@ function block_content_update_10100(&$sandbox = NULL): TranslatableMarkup {
$entityDefinitionUpdateManager->updateEntityType($definition);
return \t('Added revision routes to Custom block entity type.');
}
/**
* Remove the unique values constraint from block content info fields.
*/
function block_content_update_10200() {
$constraint = 'UniqueField';
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_storage_definition = $definition_update_manager->getFieldStorageDefinition('info', 'block_content');
$constraints = $field_storage_definition->getConstraints();
if (isset($constraints[$constraint])) {
unset($constraints[$constraint]);
$field_storage_definition->setConstraints($constraints);
$definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
}
}
......@@ -215,8 +215,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
'type' => 'string_textfield',
'weight' => -5,
])
->setDisplayConfigurable('form', TRUE)
->addConstraint('UniqueField', []);
->setDisplayConfigurable('form', TRUE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
......
......@@ -70,15 +70,6 @@ public function testBlockContentCreation() {
->loadByProperties(['info' => $edit['info[0][value]']]);
$block = reset($blocks);
$this->assertNotEmpty($block, 'Custom Block found in database.');
// Check that attempting to create another block with the same value for
// 'info' returns an error.
$this->drupalGet('block/add/basic');
$this->submitForm($edit, 'Save');
// Check that the Basic block has been created.
$this->assertSession()->pageTextContains('A custom block with block description ' . $edit['info[0][value]'] . ' already exists.');
$this->assertSession()->statusCodeEquals(200);
}
/**
......@@ -148,15 +139,6 @@ public function testBlockContentCreationMultipleViewModes() {
->loadByProperties(['info' => $edit['info[0][value]']]);
$block = reset($blocks);
$this->assertNotEmpty($block, 'Custom Block found in database.');
// Check that attempting to create another block with the same value for
// 'info' returns an error.
$this->drupalGet('block/add/basic');
$this->submitForm($edit, 'Save');
// Check that the Basic block has been created.
$this->assertSession()->pageTextContains('A custom block with block description ' . $edit['info[0][value]'] . ' already exists.');
$this->assertSession()->statusCodeEquals(200);
}
/**
......
<?php
namespace Drupal\Tests\block_content\Functional;
use Drupal\Component\Render\FormattableMarkup;
/**
* Tests block content validation constraints.
*
* @group block_content
*/
class BlockContentValidationTest extends BlockContentTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests the block content validation constraints.
*/
public function testValidation() {
// Add a block.
$description = $this->randomMachineName();
$block = $this->createBlockContent($description, 'basic');
// Validate the block.
$violations = $block->validate();
// Make sure we have no violations.
$this->assertCount(0, $violations);
// Save the block.
$block->save();
// Add another block with the same description.
$block = $this->createBlockContent($description, 'basic');
// Validate this block.
$violations = $block->validate();
// Make sure we have 1 violation.
$this->assertCount(1, $violations);
// Make sure the violation is on the info property
$this->assertEquals('info', $violations[0]->getPropertyPath());
// Make sure the message is correct.
$this->assertEquals(new FormattableMarkup('A custom block with Block description %value already exists.', ['%value' => $block->label()]), $violations[0]->getMessage());
}
}
<?php
namespace Drupal\Tests\block_content\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests the upgrade path for removing unique constraint on blocks.
*
* @group block_content
*/
class BlockContentRemoveConstraint extends UpdatePathTestBase {
/**
* Entity definition update manager.
*
* @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface
*/
protected $entityDefinitionUpdateManager;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->entityDefinitionUpdateManager = \Drupal::entityDefinitionUpdateManager();
}
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-9.4.0.filled.standard.php.gz',
];
}
/**
* Tests the upgrade path for moderation state reindexing.
*/
public function testRunUpdates() {
$constraint = 'UniqueField';
$constraints = $this->getFieldInfoConstraints();
if (!isset($constraints[$constraint])) {
$constraints[$constraint] = [];
$field_storage_definition = $this->entityDefinitionUpdateManager->getFieldStorageDefinition('info', 'block_content');
$field_storage_definition->setConstraints($constraints);
$this->entityDefinitionUpdateManager->updateFieldStorageDefinition($field_storage_definition);
}
$this->assertCount(2, $this->getFieldInfoConstraints());
$this->runUpdates();
$this->assertCount(1, $this->getFieldInfoConstraints());
}
/**
* Get constraints for info field.
*
* @return array[]
* List of constraints.
*/
protected function getFieldInfoConstraints() {
$field_storage_definition = $this->entityDefinitionUpdateManager->getFieldStorageDefinition('info', 'block_content');
return $field_storage_definition->getConstraints();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment