Hi,

when i try to add an captcha-field to my newsletter-subscriber-block (form) it says the maschine name is too long:

Machine-readable name cannot be longer than 64 characters but is currently 67 characters long.

the maschine name looks like this:

simplenews_subscriptions_block_ec02ad7a-09b9-4072-82d5-702435291c2c

how can i fix this?

best,

Comments

lolhonk created an issue. See original summary.

ModernMantra’s picture

Status: Needs work » Needs review
StatusFileSize
new1.36 KB

Had some little discussion with @berdir. Possible solution is to input from user unique id, if not than generate one. So, for now little progress, will do some more work on this later...

berdir’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

The default value should be the current uuid configuration. And it should have a description that explains this ID and how it should be used: to have a predictable form ID, if set, the user is responsible for making it unique, if not set, a random value will be generated.

We could also use a shorter mechanism to generate the unique Id, it doesn't have to be a UUID.

ModernMantra’s picture

Status: Needs work » Needs review
StatusFileSize
new1.5 KB
new1.2 KB

Some small improvements considering comment #3 (in addition noticed some redundant parts of code which is removed). Still there has to be done more work especially in two things:
- test coverage
- another method for generating ID
I was trying to find appropriate test class to test the input field. but did not succeed (tried with SimplenewsSubscribeTest and SimplenewsTestSubscriptionOutput and runned all test in simplenews with breakpoint placed in SimplenewsSUbscriptionBlock but it was not triggered by any test class, or i was doing something wrong)

berdir’s picture

Status: Needs review » Needs work

As discussed, blocks are currently only created through the API.

ModernMantra’s picture

Status: Needs work » Needs review
StatusFileSize
new1.96 KB
new1.38 KB
new2.88 KB

Now, there is test support. :-)

The last submitted patch, 6: captcha-2799175-TEST_ONLY-6.patch, failed testing.

toncic’s picture

Status: Needs review » Needs work

I think that we need screenshot for this issue, this is kind of UI change.

ModernMantra’s picture

Status: Needs work » Needs review
StatusFileSize
new54.64 KB

Here is the screenshot :-)

berdir’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests
  1. +++ b/src/Plugin/Block/SimplenewsSubscriptionBlock.php
    @@ -120,6 +120,14 @@ class SimplenewsSubscriptionBlock extends BlockBase implements ContainerFactoryP
    +      '#description' => t('You are responsible for making ID unique. If it is not set, random value will be generated.'),
    

    "Each subscription block must have a unique form ID. If no value is provided, a random ID will be generated. Use this to have a predictable, short ID, e.g. to configure this form to use a CAPTCHA."

  2. +++ b/src/Plugin/Block/SimplenewsSubscriptionBlock.php
    @@ -149,7 +157,8 @@ class SimplenewsSubscriptionBlock extends BlockBase implements ContainerFactoryP
    -    $this->configuration['unique_id'] = \Drupal::service('uuid')->generate();
    +    $unique_input = $form_state->getValue('unique_id');
    +    $this->configuration['unique_id'] = (empty($unique_input)) ? \Drupal::service('uuid')->generate() : $unique_input;
    

    Can be simplified to $form_state->getValue('unique_id') ?: ...generate()

  3. +++ b/src/Tests/SimplenewsAdministrationTest.php
    @@ -1008,4 +1008,28 @@ class SimplenewsAdministrationTest extends SimplenewsTestBase {
     
    +  /**
    +   * Tests Creation of Simplenews Subscription block.
    +   */
    +  public function testSimplenewsSubscriptionBlock() {
    +    $admin_user = $this->drupalCreateUser(array(
    +      'administer blocks',
    

    existing subscription block tests are I think mostly in SimplenewsSubscribeTest

  4. +++ b/src/Tests/SimplenewsAdministrationTest.php
    @@ -1008,4 +1008,28 @@ class SimplenewsAdministrationTest extends SimplenewsTestBase {
    +    $this->assertLinkByHref('/admin/structure/block/add/simplenews_subscription_block/classy', 0,
    +      'Did not find the Simplenews Subscription block in block candidate list.');
    +    $block = $this->drupalPlaceBlock('simplenews_subscription_block', array(
    +      'unique_id' => 'test_block_simplenews_123',
    +    ));
    

    still no.

    Don't just look for a link. Go there and fill out the form. You are just testing the core block UI. Don't, that's not our job. Just go directly to that link and fill out the form.

    Forget about drupalPlaceBlock().

  5. +++ b/src/Tests/SimplenewsAdministrationTest.php
    @@ -1008,4 +1008,28 @@ class SimplenewsAdministrationTest extends SimplenewsTestBase {
    +    $this->drupalGet('admin/structure/block/manage/' . $block->id());
    +    $this->assertText('Unique ID');
    +    $this->assertFieldByName('settings[unique_id]', 'test_block_simplenews_123', 'Unique ID field is properly set.');
    

    We want to check that the value is kept and shown in the settings too, yes. But that should be done in the first test.

    Here, we need to assert on the frontpage that the unique ID is actually *used* for the form_id of the form.

ModernMantra’s picture

Status: Needs work » Needs review
StatusFileSize
new3.18 KB
new4.54 KB

Moved the test to SImplenewsSubscribeTest and imprved all stuff pointed in comment #10.

Status: Needs review » Needs work

The last submitted patch, 11: captcha-2799175-11.patch, failed testing.

ModernMantra’s picture

Status: Needs work » Needs review

IMHO, test fails are random one and does not have too much to do with my patch, or maybe i am wrong... Setting to needs review to trigger someones revision :-)

berdir’s picture

  1. +++ b/src/Tests/SimplenewsSubscribeTest.php
    @@ -876,4 +876,32 @@ class SimplenewsSubscribeTest extends SimplenewsTestBase {
    +    $this->drupalGet('admin/structure/block');
    +    $this->clickLinkPartialName('Place block');
    +    $this->assertLinkByHref('/admin/structure/block/add/simplenews_subscription_block/classy', 0,
    +      'Did not find the Simplenews Subscription block in block candidate list.');
    

    this part can go. just going to the page on the line below is enough for us, those links are the core block UI, we don't need to test that.

  2. +++ b/src/Tests/SimplenewsSubscribeTest.php
    @@ -876,4 +876,32 @@ class SimplenewsSubscribeTest extends SimplenewsTestBase {
    +    $this->assertText('The block configuration has been saved.');
    +    $this->drupalPostForm(NULL,array(), 'Save blocks');
    

    this shouldn't be needed.

ModernMantra’s picture

StatusFileSize
new2.79 KB
new1.15 KB

Improvements considering previous comment :)

ModernMantra’s picture

StatusFileSize
new27.22 KB

In order to close the issue, we need to check integration together with Captcha module. So by discussion and help from @berdir, installed modules and placed captcha on block. So, it works and attaching the screenshot to verify that.

  • Berdir committed 0787877 on 8.x-1.x authored by ModernMantra
    Issue #2799175 by ModernMantra: Make the unique ID in subscription...
berdir’s picture

Title: Problem with Captcha/Recaptcha » Make the unique ID in subscription blocks configurable, to have a predictable form ID for CAPTCHA
Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.