Skip to content

Bundled avatar generators do not merge configuration correctly #43

@ao2

Description

@ao2

Hi,

I am testing 8.x-1.0 with Drupal 8.4 and I get this notice when enabling the Gravatar generator:

Notice: Undefined index: maximum_rating in Drupal\avatars_gravatar\Plugin\AvatarGenerator\Gravatar->buildConfigurationForm() (line 74 of modules/contrib/avatars/avatars_gravatar/src/Plugin/AvatarGenerator/Gravatar.php).

Drupal\avatars_gravatar\Plugin\AvatarGenerator\Gravatar->buildConfigurationForm(Array, Object) (Line: 110)
Drupal\avatars\Form\AvatarGeneratorForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('avatar_generator_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('avatar_generator_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 576)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 153)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

From a quick look at the code it seems that AvatarGeneratorBase::setConfiguration() is called after the plugin creation and overrides the values set by Gravatar::defaultConfiguration().

This change works around the issue but I am not sure if it's the proper fix:

diff --git a/src/Plugin/AvatarGenerator/AvatarGeneratorBase.php b/src/Plugin/AvatarGenerator/AvatarGeneratorBase.php
index 84ff513..c19a407 100644
--- a/src/Plugin/AvatarGenerator/AvatarGeneratorBase.php
+++ b/src/Plugin/AvatarGenerator/AvatarGeneratorBase.php
@@ -42,7 +42,7 @@ abstract class AvatarGeneratorBase extends PluginBase implements AvatarGenerator
    * {@inheritdoc}
    */
   public function setConfiguration(array $configuration) {
-    $this->configuration = $configuration;
+    $this->configuration = array_merge($this->configuration, $configuration);
   }
 
   /**

I also noticed that when I leave the maximum content rating to Unrestricted and try to save, the modules refuses to save the setting with this message:

Maximum content rating field is required.

That could make sense (forcing a maximum rating) but the interface is not very user friendly: the user doesn't know that Unrestricted corresponds to an empty value under the hood.

Maybe the message can be improved, or g can be used as a default and the Unrestricted option can be removed completely.

Thanks,
Antonio

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions