[CONTEDIT-77] Default block doesn't work Created: 30/Mar/17  Updated: 10/Apr/17  Resolved: 04/Apr/17

Status: Closed
Project: Content Editor
Component/s: None
Affects Version/s: None
Fix Version/s: 1.0.1

Type: Bug Priority: Blocker
Reporter: Mariusz Chruscielewski Assignee: Aleksandr Pchelintcev
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Capture.PNG     PNG File screenshot-1.png     PNG File screenshot-2.png     PNG File screenshot-3.png     PNG File screenshot-4.png    
Issue Links:
Relates
relates to CONTEDIT-81 Initial block in content definition i... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Epic Link: Content Editor fine-tuning
Sprint: Basel 90
Story Points: 3

 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:


Generated at Mon Feb 12 00:16:50 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.