backdrop-contrib / paragraphs

Paragraphs module to control your content flow
https://backdropcms.org/project/paragraphs
GNU General Public License v2.0
5 stars 11 forks source link

Dummy value to the paragraphs field causing issue #196

Open sudipto68 opened 1 month ago

sudipto68 commented 1 month ago

There is a function in the paragraph module's paragraphs.field_formatter.inc file like this:

/**
 * Implements hook_field_prepare_view().
 *
 * Adds a dummy value to the paragraphs field to make rendering possible.
 */
function paragraphs_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
  if ($field['type'] == 'paragraphs') {
    foreach ($items as $key => $item) {
      if (!isset($item[0]['value'])) {
        $items[$key][0]['value'] = 'scratch_paragraph';
      }
    }
  }
}

This function adds a dummy value scratch_paragraph in paragraph fields. For this dummy value, we faced an weird issue in our site. We have a paragraph(i.e. Accordion) that is used as a field in page content type. If we create a page and don't create any paragraph, then also the paragraph is having a dummy value in its fields, for that the HTML structure is present in the node.tpl for the paragraph fields and it is showing the design we provided in the paragraph but don't have any value.

I don't know why this function with dummy value is used? Is there any use case for this?

laryn commented 1 month ago

@sudipto68 This 'scratch_paragraph' concept is not fully fleshed out, I'm afraid, but is/was intended to allow sites with front end modal editing enabled to insert a new paragraph from the front end, even if no paragraphs items are already present. In this case it would need to insert a blank "scratch paragraph" at the insertion point. At a minimum it should be checking that modal administration is activated and the current user has permissions for it, but I'm tempted to just remove this for now and when/if we bring this functionality in, we can do it all at once, cleanly...