Uploaded image for project: 'Content Editor'
  1. Content Editor
  2. CONTEDIT-77

Default block doesn't work

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Blocker
    • 1.0.1
    • None
    • None

    Description

      Hi, if we use custom block as defaultBlock in app.yaml , it doesn't render anything (we get X and +, but not block content)

      After changing theme to content-editor, I can see that there is "text" block always rendered by default, but if you save it empty, you can't open item again:

      Caused by: javax.jcr.PathNotFoundException: mgnl:type
      at org.apache.jackrabbit.core.NodeImpl$11.perform(NodeImpl.java:2265)
      at org.apache.jackrabbit.core.NodeImpl$11.perform(NodeImpl.java:2252)
      at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
      at org.apache.jackrabbit.core.ItemImpl.perform(ItemImpl.java:91)

      Another problem is that you can't do anything to avoid having 1 block without mgnl:type, please look below:

      Article created - default block deleted - custom added - only one block, saved:

      In SaveContentAction, then we call "this.body.getBlocks()", I get 2 elements (my custom block & default one).

      Then in JCR I have:

      Please note that first one doesn't have mgnl:type

      That is a blocker.

      EDIT:

      I tried to make a workaround, and always delete first block if it's empty text, but then I get even more strange results.

      Save action that does deletion:

       @Override
          protected void save() throws RepositoryException {
      
              if (this.contentOutline.isValid()) {
                  List originalBlocks = this.body.getBlocks();
                  if (!this.blocksAreValid(originalBlocks)) {
                      return;
                  }
      
                  /**
                   * Dirty hack to remove first block if it's TEXT, this is due to Magnolia Bug:
                   * https://jira.magnolia-cms.com/browse/CONTEDIT-77
                   */
                  List blocks;
                  if (originalBlocks.get(0) instanceof RichTextBlock) {
                      blocks = new ArrayList();
                      for (int i = 1; i < originalBlocks.size(); i++) {
                          blocks.add(originalBlocks.get(i));
                      }
                  } else {
                      blocks = originalBlocks;
                  }
                  /**
                   * END OF HACK
                   */
                  String oldURL = "";
                  if (!jcrNodeAdapter.isNew()) {
                      oldURL = newsItemListService.getRelativePublicUrl(jcrNodeAdapter.getJcrItem());
                  }
      
                  Node node = this.jcrNodeAdapter.applyChanges();
                  SaveActionUtils.setNodeName(node, this.jcrNodeAdapter, getDefinition().getPropertyName(), solrSettingsWrapper);
                  String newUrl = newsItemListService.getRelativePublicUrl(node);
      
                  if (!jcrNodeAdapter.isNew() && !StringUtils.equalsIgnoreCase(oldURL, newUrl)) {
                      List<String> oldUrlsList = new ArrayList<>();
                      if (node.hasProperty(OLD_URLS_JCR_PROPERTY_NAME)) {
                          oldUrlsList = PropertyUtil.getValuesStringList(node.getProperty(OLD_URLS_JCR_PROPERTY_NAME).getValues());
                      }
                      oldUrlsList.add(oldURL);
                      ExtendedPropertyUtil.setProperty(node, OLD_URLS_JCR_PROPERTY_NAME, oldUrlsList);
                  }
                  ExtendedPropertyUtil.setProperty(node, ARTICLE_URL_JCR_PROPERTY_NAME, newsItemListService.getRelativePublicUrl(node));
                  node.getSession().save();
                  this.applyBlockChanges(blocks);
                  this.uiContext.openNotification(MessageStyleTypeEnum.INFO, true, this.getDefinition().getSuccessMessage());
              }
          }
      

      Block definition ( we have few, but they are all built the same way):

      class: info.magnolia.editor.content.block.stock.FieldSetBlockDefinition
      templateId: vinl-website:blocks/common/richTextBlock
      fields:
        text:
          label: Tekst
        #For now we can't use rich text editor here
          class: info.magnolia.ui.form.field.definition.TextFieldDefinition
      #    images: false
      #    height: 200
      
      

      Result of "deletion" in JCR:

      Checklists

        Acceptance criteria

        Attachments

          1. Capture.PNG
            Capture.PNG
            62 kB
          2. screenshot-1.png
            screenshot-1.png
            138 kB
          3. screenshot-2.png
            screenshot-2.png
            148 kB
          4. screenshot-3.png
            screenshot-3.png
            122 kB
          5. screenshot-4.png
            screenshot-4.png
            49 kB

          Issue Links

            Activity

              People

                apchelintcev Aleksandr Pchelintcev
                mchruscielewski Mariusz Chruscielewski
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  Checklists

                    Bug DoR
                    Task DoD