Uploaded image for project: 'eZ Platform Enterprise Edition'
  1. eZ Platform Enterprise Edition
  2. EZEE-699

Not required empty block field prevents submission of configure popup

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: High High
    • Resolution: Fixed
    • Affects Version/s: 16.02, Customer request
    • Fix Version/s: 16.04, 1.3.1, 1.4.0-beta1
    • Component/s: Studio UI
    • Labels:
      None

      Description

      Create a new basic block with two embed Block attributes.
      Make the first attribute required.
      Make the second one optional.

      Add the block to a zone and click the configure button.
      Add an item to the required attribute and leave the other one empty as default.

      Clicking on submit shakes the dialog box indicating an error, but no error message is displayed.

        Issue Links

          Activity

          Hide
          Michał Szołtysek added a comment -

          QA Approved

          Show
          Michał Szołtysek added a comment - QA Approved
          Show
          Piotr Nalepa added a comment - PR merged to 1.2: https://github.com/ezsystems/StudioUIBundle/commit/b51cadbd4578a264625891995d0f07b032a05520
          Hide
          Peter Halasz added a comment - - edited

          The block class for the block with the issues:

          <?php
           
          namespace Example\EzStudio\FieldType\LandingPage\Model\Block;
           
          use eZ\Publish\API\Repository\ContentService;
          use EzSystems\LandingPageFieldTypeBundle\Exception\InvalidBlockAttributeException;
          use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Definition\BlockDefinition;
          use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Definition\BlockAttributeDefinition;
          use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Model\AbstractBlockType;
          use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Model\BlockType;
          use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Model\BlockValue;
           
          /**
           * List Card block
           * Renders content from given location.
           */
          class ListCardBlock extends AbstractBlockType implements BlockType
          {
              /**
               * @var ContentService
               */
              private $contentService;
           
              /**
               * @param ContentService $contentService
               */
              public function __construct(ContentService $contentService)
              {
                  $this->contentService = $contentService;
              }
           
              /**
               * {@inheritdoc}
               */
              public function getTemplateParameters(BlockValue $blockValue)
              {
                  $attributes = array_filter($blockValue->getAttributes(), function ($attribute) {
                      return !empty($attribute);
                  });
           
                  $articleLocationIds = array_map(function ($attribute) {
                      return $this->contentService->loadContentInfo($attribute)->mainLocationId;
                  }, $attributes);
           
                  return ['articleLocationIds' => $articleLocationIds];
              }
           
              /**
               * {@inheritdoc}
               */
              public function createBlockDefinition()
              {
                  $blockAttributeDefinitions = array_map(function ($index) {
                      return new BlockAttributeDefinition(
                          sprintf('article_%d_Id', $index),
                          sprintf('Article %d', $index),
                          'embed',
                          '/^([a-zA-Z]:)?(\/[a-zA-Z0-9_\/-]+)+\/?/',
                          'Choose an Article',
                          $index == 1
                      );
                  }, range(1, 4));
           
                  return new BlockDefinition(
                      'listcard',
                      'List Card',
                      'default',
                      'bundles/ezsystemslandingpagefieldtype/images/thumbnails/contentlist.svg',
                      [],
                      $blockAttributeDefinitions
                  );
              }
           
              /**
               * {@inheritdoc}
               */
              public function checkAttributesStructure(array $attributes)
              {
                  if (!isset($attributes['article_1_Id'])) {
                      throw new InvalidBlockAttributeException('ListCard', 'article_1_Id', 'You need to select at least 1 item.');
                  }
           
                  if (!is_numeric($attributes['article_1_Id'])) {
                      throw new InvalidBlockAttributeException('ListCard', 'article_1_Id', 'Content ID must be type of integer.');
                  }
              }
          }
          

          Part from the services configuration for the block:

          <service id="ezpublish.landing_page.block.list_card" class="Example\EzStudio\FieldType\LandingPage\Model\Block\ListCardBlock">
                  <argument type="service" id="ezpublish.api.service.content"/>
           
                  <tag name="landing_page_field_type.block_type" alias="listcard"/>
          </service>
          

          Show
          Peter Halasz added a comment - - edited The block class for the block with the issues: <?php   namespace Example\EzStudio\FieldType\LandingPage\Model\Block;   use eZ\Publish\API\Repository\ContentService; use EzSystems\LandingPageFieldTypeBundle\Exception\InvalidBlockAttributeException; use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Definition\BlockDefinition; use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Definition\BlockAttributeDefinition; use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Model\AbstractBlockType; use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Model\BlockType; use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Model\BlockValue;   /** * List Card block * Renders content from given location. */ class ListCardBlock extends AbstractBlockType implements BlockType { /** * @var ContentService */ private $contentService;   /** * @param ContentService $contentService */ public function __construct(ContentService $contentService) { $this->contentService = $contentService; }   /** * {@inheritdoc} */ public function getTemplateParameters(BlockValue $blockValue) { $attributes = array_filter($blockValue->getAttributes(), function ($attribute) { return !empty($attribute); });   $articleLocationIds = array_map(function ($attribute) { return $this->contentService->loadContentInfo($attribute)->mainLocationId; }, $attributes);   return ['articleLocationIds' => $articleLocationIds]; }   /** * {@inheritdoc} */ public function createBlockDefinition() { $blockAttributeDefinitions = array_map(function ($index) { return new BlockAttributeDefinition( sprintf('article_%d_Id', $index), sprintf('Article %d', $index), 'embed', '/^([a-zA-Z]:)?(\/[a-zA-Z0-9_\/-]+)+\/?/', 'Choose an Article', $index == 1 ); }, range(1, 4));   return new BlockDefinition( 'listcard', 'List Card', 'default', 'bundles/ezsystemslandingpagefieldtype/images/thumbnails/contentlist.svg', [], $blockAttributeDefinitions ); }   /** * {@inheritdoc} */ public function checkAttributesStructure(array $attributes) { if (!isset($attributes['article_1_Id'])) { throw new InvalidBlockAttributeException('ListCard', 'article_1_Id', 'You need to select at least 1 item.'); }   if (!is_numeric($attributes['article_1_Id'])) { throw new InvalidBlockAttributeException('ListCard', 'article_1_Id', 'Content ID must be type of integer.'); } } } Part from the services configuration for the block: <service id="ezpublish.landing_page.block.list_card" class="Example\EzStudio\FieldType\LandingPage\Model\Block\ListCardBlock"> <argument type="service" id="ezpublish.api.service.content"/>   <tag name="landing_page_field_type.block_type" alias="listcard"/> </service>
          Hide
          Kamil Musiał (Inactive) added a comment - - edited

          I cannot reproduce this bug. Everything works fine in my env. Please provide your block class and services.yml file with config of this service.

          Show
          Kamil Musiał (Inactive) added a comment - - edited I cannot reproduce this bug. Everything works fine in my env. Please provide your block class and services.yml file with config of this service.

            People

            • Assignee:
              Unassigned
              Reporter:
              Peter Halasz
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: