Problem:

Sometimes you don't want to show the "About text formats" link, especially if you just allow a single format on a field and therefore there is no format selector and so the link is taking up vertical space on its own.

Sometimes you don't want to show the condensed text format guidelines below a field, especially on "text, formatted" fields where the guidelines take up more space than the field input itself.

Although the main focus of this module is controlling the allowed text formats, it also seems to be an incubator for core improvements in sitebuilder control of formats UI, so it seems reasonable to include this feature.

Solution:

Create 2 new widget settings checkboxes: "Hide the help link About text formats" and "Hide text format guidelines".
The patch by @floretan from #15 works and is ready for testing & review.

Next steps:

DONE: 1. Fix the config schema in the patch
2. Review & RTBC

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir created an issue. See original summary.

floretan’s picture

Status: Active » Needs work

I agree that this is a good improvement. It's not directly related to limiting formats, but the fact that these tips are useless becomes particularly visible once you limit the available formats.

jcnventura’s picture

Adding a related issue from back when this module lived as a core patch.

jonathanshaw’s picture

Title: Allow to control if format help/tips should be shown or not » Allow to control if "About text formats" link should be shown or not
Berdir’s picture

I disagree with that title change, it's not just about that IMHO, it also about hiding the short explanation that is shown there.

jonathanshaw’s picture

@Berdir I was trying to distinguish this issue from #2629618: Allow to hide text format help text for Text(formatted) perhaps there are angles I've overlooked?

Berdir’s picture

Ah. I'm not sure if it needs to be distinguished or if this issue is simply a duplicate. Not sure if there's a use case for controlling the link and the bullet points separately or if a single checkbox to hide both is enough?

jonathanshaw’s picture

Fair question; on further thought I think there is a significant use case:

The set of bullet points that are present for only Text (formatted) take up a lot of space. Sometimes one might well wish to hide the bullets, but leave the "About text formats" link as that gives a way to access that help that is much less cluttering.

One could say that it's not an issue for this module directly - it's not related at all to controlling the allowed text formats - but as this module seems to be an incubator for core improvements in sitebuilder control of formats UI (and has this closely related issue) I thought it made sense to file here?

floretan’s picture

I don't have time to write the full implementation, but here's the basic code to hide the help text. Due to the way the formatted text widgets are structured, the code is really ugly. We should be able to get something much nicer in core.

/**
 * Implements hook_field_widget_form_alter().
 */
function allowed_formats_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
  if ($context['widget'] instanceof \Drupal\text\Plugin\Field\FieldWidget\TextareaWidget) {
    $element['#after_build'][] = '_allowed_formats_remove_textarea_help';
  }
}

/**
 * #after_build callback.
 */
function _allowed_formats_remove_textarea_help($form_element, FormStateInterface $form_state) {
  if (isset($form_element['format'])) {
    // All this stuff is needed to hide the help text.
    unset($form_element['format']['guidelines']);
    unset($form_element['format']['help']);
    unset($form_element['format']['#type']);
    unset($form_element['format']['#theme_wrappers']);
  }

  return $form_element;
}

Before this can be committed, we basically need to extend the formatted text widget with the relevant options and to read that configuration to determine what should be hidden. The tests should also be adapted.

jcnventura’s picture

Turning #9 into code that can be used. Since this can be applied to more than textareas, I've removed that check, and replaced with a simple check for single allowed formats.

This still needs improvements to tests and possibly some configuration at widget level whether the configuration should be hidden or not.

reekris’s picture

Status: Needs work » Needs review
reekris’s picture

Status: Needs review » Needs work
jcnventura’s picture

Version: 8.x-1.x-dev » 8.x-1.0
Status: Needs work » Needs review
FileSize
2.27 KB

The last patch no longer applies cleanly, I'm rerolling the patch and adding the requested setting to hide the help text. It only applies when only a single text format is applicable.

jonathanshaw’s picture

Great to see some work on this. 3 points of feedback:

1. There seems to be a bug when I test it: when there is only 1 format allowed, both help link and guidelines are always hidden regardless of "Hide text format guidelines" checkbox value.

2. It seems wrong to be setting "Hide text format guidelines" on the field settings; as I think you implied before, it would seem better to have this as a widget setting not a field setting; it is a UI setting not a data storage setting.

3. "Hide text format guidelines when only a single format is allowed." I'm not clear if the intention is to hide the "About text formats" link or the text format guidelines that show up only for text(formatted) fields or both. Could you clarify?

floretan’s picture

Here's a reworked version of the patch that integrates the feedback from @jonathanjfshaw:

  1. Moved the "hide" settings from the field third party settings to the widget third party settings (also takes care of the bug in the first point).
  2. Split between two checkboxes: "Hide the help link About text formats." and "Hide text format guidelines."
  3. The wrapper is then hidden if the help link, then guidelines and the format selector are all hidden.

Leaving this as "needs review", since the config schema changes included in the patch are not valid anymore.

jonathanshaw’s picture

Title: Allow to control if "About text formats" link should be shown or not » Control "About text formats" link and inline text format guidelines
Issue summary: View changes

That approach works perfectly for me when I test it.

jonathanshaw’s picture

pucowanje’s picture

Applied patch #15. Works perfectly for me. Thanks! Would be nice to have this in the module.

John Pitcairn’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

Patch #15 works for me against 1.0 and 1.x-dev.

jonathanshaw’s picture

What action is needed to deal with #15's remark:

Leaving this as "needs review", since the config schema changes included in the patch are not valid anymore.

John Pitcairn’s picture

@floretan can you clarify what (if anything) needs to be done about the config shema changes?

leisurman’s picture

This worked for me for drupal 8. Custom module file. You have to place in your field machine name

<?php

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_field_widget_form_alter().
 */
function YOURMODULENAME_form_alter(&$form, &$form_state, &$form_id) {
    $form['field_short_description']['widget']['#after_build'][] = '_allowed_formats_remove_textarea_help';
}

function _allowed_formats_remove_textarea_help($form_element, FormStateInterface $form_state) {
  if (isset($form_element[0]['format'])) {
    // All this stuff is needed to hide the help text.
    unset($form_element[0]['format']['guidelines']);
    unset($form_element[0]['format']['help']);
    unset($form_element[0]['format']['#type']);
    unset($form_element[0]['format']['#theme_wrappers']);
    $form_element[0]['format']['format']['#access'] = FALSE;
  }

  return $form_element;
}
leisurman’s picture

I tried to get #9 to work but this is simular and it worked for me.
https://www.drupal.org/node/2617982#comment-11908620

AdamPS’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
FileSize
3.65 KB

Patch updated to include required schema changes

Tested free of schema errors using module config_inspector.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks good thanks, back to RTBC.

  • floretan committed eabd7e0 on 8.x-1.x authored by AdamPS
    Issue #2617982 by jcnventura, floretan, AdamPS: Control "About text...
floretan’s picture

Status: Reviewed & tested by the community » Fixed

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Foxy-vikvik’s picture

After using patches has error message