Description

The text_format field doesn't display a full editor anymore, only a basic input field. In the beta7 version, it displays the editor correctly but doesn't save. The latest 8.0.x-dev version inverts that bug (it saves the contents of the field, but doesn't display correctly — same code).

Steps to reproduce

  • Install Drupal 8.0.x-dev
  • Create an entity
  • Configure the add route for the entity
  • Put the following code in the baseFieldDefinitions method for the entity:
    $fields['content'] = BaseFieldDefinition::create('text')
          ->setLabel(t('Content'))
          ->setDescription(t('The content of the block'))
          ->setSettings(array(
            'max_length'  => 1024
          ))
          ->setDisplayOptions('form', array(
            'type'   => 'text_format',
            'weight' => -6
          ))
          ->setRequired(TRUE)
          ->setDisplayConfigurable('form', TRUE);
    
  • Go to the add page for the entity, see the result
  • Update composer.json by changing the drupal/core version to "~8.0"
  • Run composer update and clear cache
  • Go to the add page again and see the field displaying just fine

Expected result (display on 8.0.0-beta7)

expected screenshot

Obtained result (display on 8.0.x-dev)

obtained screenshot

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

idebr’s picture

Status: Active » Closed (works as designed)
Related issues: +#2442255: Changing text formats on a field makes it impossible to edit.

@PLPeeters thanks for submitting a bug report! The editor was purposefully removed because CKEditor is currently only compatible with textarea (and incompatible with textfield). For more information, please have a look at the issue where this was resolved: #2442255: Changing text formats on a field makes it impossible to edit.

PLPeeters’s picture

@idebr Thanks for clearing that up. Reading through the comments, I noticed it's still possible to attach an editor, but I couldn't understand how. Could you tell me where I can figure that out?

idebr’s picture

@PLPeeters The possibilities suggested in #2442255: Changing text formats on a field makes it impossible to edit. are either:
- Use a WYSIWYG editor that is compatible with a textfield (eg. not CKEditor)
- Use a textarea instead of a textfield to use CKEditor

PLPeeters’s picture

@idebr Using a textarea seems to be the appropriate option in my case, however the description for text_format in the documentation for the Form API is "A text-format-enabled version of a textarea", so apparently it's already supposed to be a textarea. I guess there's something I'm not understanding correctly here. Could you enlighten me?

PLPeeters’s picture

Just for the record for anyone who might stumble across this problem in the future, the solution was to change the definition of my field to text_long and the type to text_textarea, like this:

$fields['content'] = BaseFieldDefinition::create('text_long')
      ->setLabel(t('Content'))
      ->setDescription(t('The content of the block'))
      ->setDisplayOptions('form', array(
        'type'   => 'text_textarea',
        'weight' => -6
      ))
      ->setRequired(TRUE)
      ->setDisplayConfigurable('form', TRUE);
michael.romero’s picture

configuration to have a field with full editor (Textarea):

$fields['description'] = BaseFieldDefinition::create('text_long')
      ->setLabel(t('Description'))
      ->setDescription(t('The description.'))
      ->setRevisionable(TRUE)
      ->setSettings([
        'max_length' => 1000,
        'text_processing' => 0,
      ])
      ->setDefaultValue('')
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'string',
        'weight' => -4,
      ])
      ->setDisplayOptions('form', [
        'type' => 'text_textarea ',
        'rows' => 0,
        'weight' => -4,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE)
      ->setRequired(TRUE);