summaryrefslogtreecommitdiffstats
path: root/core/modules/breakpoint
diff options
context:
space:
mode:
authorcatch2014-03-30 15:02:28 +0200
committercatch2014-03-30 15:02:28 +0200
commit979bb625cefb89a893dfe03e3fc8cca6e243c9f4 (patch)
tree1649741c22be782e6d9f1f9552f5bdbafcf6c81a /core/modules/breakpoint
parent669b898b86e4209f7d6e8e0b191ef4ddf2313dcf (diff)
Issue #2226027 by tim.plunkett: ConfigEntityBase::preSave() tries to load the original entity but instead loads itself.
Diffstat (limited to 'core/modules/breakpoint')
-rw-r--r--core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php19
-rw-r--r--core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php13
-rw-r--r--core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php6
-rw-r--r--core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php2
4 files changed, 28 insertions, 12 deletions
diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php
index e200894..5fa0260 100644
--- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php
+++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/Breakpoint.php
@@ -106,6 +106,18 @@ class Breakpoint extends ConfigEntityBase implements BreakpointInterface {
public $multipliers = array();
/**
+ * {@inheritdoc}
+ */
+ public function id() {
+ // If no ID is specified, build one from the properties that uniquely define
+ // this breakpoint.
+ if (!isset($this->id)) {
+ $this->id = $this->sourceType . '.' . $this->source . '.' . $this->name;
+ }
+ return $this->id;
+ }
+
+ /**
* Overrides Drupal\config\ConfigEntityBase::save().
*/
public function save() {
@@ -114,13 +126,6 @@ class Breakpoint extends ConfigEntityBase implements BreakpointInterface {
throw new InvalidBreakpointException('Invalid data detected.');
}
- // Build an id if none is set.
- // Since a particular name can be used by multiple theme/modules we need
- // to make a unique id.
- if (empty($this->id)) {
- $this->id = $this->sourceType . '.' . $this->source . '.' . $this->name;
- }
-
// Set the label if none is set.
if (empty($this->label)) {
$this->label = $this->name;
diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php
index 9840657d..595ca76 100644
--- a/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php
+++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php
@@ -104,10 +104,19 @@ class BreakpointGroup extends ConfigEntityBase implements BreakpointGroupInterfa
if (!$this->isValid()) {
throw new InvalidBreakpointException('Invalid data detected.');
}
- if (empty($this->id)) {
+ parent::save();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function id() {
+ // If no ID is specified, build one from the properties that uniquely define
+ // this breakpoint group.
+ if (!isset($this->id)) {
$this->id = $this->sourceType . '.' . $this->source . '.' . $this->name;
}
- parent::save();
+ return $this->id;
}
/**
diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php
index 85d0711..e132280 100644
--- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php
+++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointAPITest.php
@@ -46,7 +46,7 @@ class BreakpointAPITest extends BreakpointTestBase {
$this->assertTrue($exception, 'breakpoint_config_name: An exception is thrown when an invalid sourceType is entered.');
// Try an invalid source.
- $breakpoint->id = '';
+ $breakpoint = $breakpoint->createDuplicate();
$breakpoint->sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED;
$breakpoint->source = 'custom*_module source';
@@ -60,7 +60,7 @@ class BreakpointAPITest extends BreakpointTestBase {
$this->assertTrue($exception, 'breakpoint_config_name: An exception is thrown when an invalid source is entered.');
// Try an invalid name (make sure there is at least once capital letter).
- $breakpoint->id = '';
+ $breakpoint = $breakpoint->createDuplicate();
$breakpoint->source = 'custom_module';
$breakpoint->name = drupal_ucfirst($this->randomName());
@@ -74,7 +74,7 @@ class BreakpointAPITest extends BreakpointTestBase {
$this->assertTrue($exception, 'breakpoint_config_name: An exception is thrown when an invalid name is entered.');
// Try a valid breakpoint.
- $breakpoint->id = '';
+ $breakpoint = $breakpoint->createDuplicate();
$breakpoint->name = drupal_strtolower($this->randomName());
$breakpoint->mediaQuery = 'all';
diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php
index 3751c81..7a563f6 100644
--- a/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php
+++ b/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupAPITest.php
@@ -49,6 +49,7 @@ class BreakpointGroupAPITest extends BreakpointGroupTestBase {
$this->assertTrue($exception, 'An exception is thrown when an invalid sourceType is entered.');
// Try an invalid source.
+ $breakpoint_group = $breakpoint_group->createDuplicate();
$breakpoint_group->name = '';
$breakpoint_group->sourceType = Breakpoint::SOURCE_TYPE_USER_DEFINED;
$breakpoint_group->source = 'custom*_module source';
@@ -63,6 +64,7 @@ class BreakpointGroupAPITest extends BreakpointGroupTestBase {
$this->assertTrue($exception, 'An exception is thrown when an invalid source is entered.');
// Try a valid breakpoint_group.
+ $breakpoint_group = $breakpoint_group->createDuplicate();
$breakpoint_group->name = 'test';
$breakpoint_group->source = 'custom_module_source';