I'm having trouble with deleted image styles and rules. This is what happens:
/**
* Implements Drupal\configuration\Config\Configuration::prepareBuild().
*/
protected function prepareBuild() {
$style = image_style_load($this->getIdentifier());
$this->style_sanitize($style);
$this->data = $style;
// Reset the order of effects, this will help to generate always the same
// hash for image styles that have been reverted.
$this->data['effects'] = array();
if (!empty($style['effects'])) {
foreach ($style['effects'] as $effect) {
$this->data['effects'][] = $effect;
}
}
return $this;
}
The above function does not check if $style actually gets loaded. It might be, however, that the style in question has been deleted and not exists. This issue can be resolved by doing the simple check below.
protected function prepareBuild() {
$style = image_style_load($this->getIdentifier());
if (empty($style)) {
$this->data = NULL;
return;
}
Also, the EntityApiConfiguration seems to not handle missing items to well. However, what is the logic for checking this? I mean, should the prepareBuild() function simply set $this->data = NULL to indicate a broken configuration? Which role does the getEntityType() function play in this? Should it also validate that the entity gets loaded (it doesn't do that now)?
In other words; what approach does this module take on determining if a configuration is "broken"?
As far as I can see, the Configuration#build() function invokes prepareBuild() which is overridden by subclasses. Am I right to assume that as long as prepareBuild() sets $this->data = NULL, then the configuration will be regarded as broken? Could it then also be that getEntityType() never gets called for broken configuration, and thus not have to be defensive in checking loaded entities? I'd be happy to provide patches for this as long as my assumptions can be verified.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | imagestyle.patch | 628 bytes | sbrattla |
| #4 | entityapi.patch | 743 bytes | sbrattla |
Comments
Comment #1
sbrattla commentedI'm working with the assumption that prepareBuild() should set $this->data = NULL if the configuration is broken. I'm attaching two patches; one to fix ImageStyleConfiguration and one to fix EntityApiConfiguration.
Comment #2
sbrattla commentedComment #3
sbrattla commentedComment #4
sbrattla commentedComment #5
sbrattla commentedUpdated patches.