Add an "Include image in display" checkbox to the image field

Created on 11 July 2013, over 11 years ago
Updated 27 October 2023, over 1 year ago

While editing filefield shows a checkbox 'List' which allows you to hide or show a link to the uploaded file in view mode. There are cases when this is usefull, for example if you manually provide a link to the file in the nodes body.
Imagefield lacks such an checkbox. It would be usefull too if you embed the uploaded image in the nodes body. Often used module Insert makes this easy with a WYSIWYG editor. Often you won't show the image twice.

Feature request:

  • Implement a similar checkbox as in filefield for imagefield.
  • Label it 'Show image'.
  • Activate by default.
Feature request
Status

Needs review

Version

11.0 🔥

Component
Image module 

Last updated 1 day ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ivnish Kazakhstan

    I implemented this. Don't work with existing fields. Needs to remove image field from content type and add again

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    Thanks for working on this old issue!

    Will need test coverage and upgrade path for existing fields.

    UI changes should have before/after screenshots added to issue summary.

    Got the issue summary started but will need updating

  • last update over 1 year ago
    Patch Failed to Apply
  • 🇮🇳India _utsavsharma

    Rerolled for 11.x as #20 failed to apply.

  • last update over 1 year ago
    30,386 pass, 33 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7 updated deps
    last update over 1 year ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Custom Commands Failed
  • last update over 1 year ago
    29,576 pass, 31 fail
  • Pipeline finished with Failed
    about 1 year ago
    Total: 481s
    #133203
  • Assigned to ivnish
  • Pipeline finished with Failed
    8 months ago
    #251740
  • Pipeline finished with Failed
    8 months ago
    Total: 556s
    #251805
  • Pipeline finished with Failed
    8 months ago
    Total: 558s
    #252506
  • Pipeline finished with Failed
    8 months ago
    Total: 154s
    #252551
  • Pipeline finished with Failed
    8 months ago
    Total: 641s
    #252555
  • Pipeline finished with Success
    8 months ago
    Total: 655s
    #253702
  • Pipeline finished with Failed
    8 months ago
    Total: 205s
    #255767
  • Pipeline finished with Success
    8 months ago
    #255768
  • Issue was unassigned.
  • Status changed to Needs review 8 months ago
  • Pipeline finished with Success
    8 months ago
    Total: 689s
    #255778
  • 🇮🇳India prashant.c Dharamshala

    While reviewing this you need to run database updates by visiting /update.php or with drush updb

     Module   Update ID              Type          Description                                              
     -------- ---------------------- ------------- --------------------------------------------------------- 
      image    add_display_checkbox   post-update   Add a table column for "Enable Display field" checkbox.  
    

    otherwise you will get this error

    The website encountered an unexpected error. Try again later.
    
    Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_image_display' in 'where clause': SELECT 1 AS "expression" FROM "node_revision__field_image" "t" WHERE ("field_image_target_id" IS NOT NULL) OR ("field_image_display" IS NOT NULL) OR ("field_image_alt" IS NOT NULL) OR ("field_image_title" IS NOT NULL) OR ("field_image_width" IS NOT NULL) OR ("field_image_height" IS NOT NULL) LIMIT 1 OFFSET 0; Array ( ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->countFieldData() (line 1789 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

    The changes are working as expected, now we have the additional checkboxes in the image field settings to display the file.

    Steps to test:

    1. Run database updates using drush or from update.php file
    2. In the content type or any other entity type add an Image field or edit any existing image field
    3. In the field settings you will find the checkboxes shown in the attached screenshots


  • 🇺🇸United States smustgrave

    Update hook does not appear to work.

    I ran it and did a drush cex and nothing was updated
    Went into admin/structure/media/manage/image/fields and resaved the field (made 0 changes)
    And get new config keys.

    Probably will need to update all image config that ships with core also.

  • Status changed to Needs work 8 months ago
  • ivnish Kazakhstan

    @smustgrave I tested again and there are results. Needs to view Drupal Status page

    1) Before patch there are no errors/warnings about any field

    2) After the patch there are errors about fields

    3) After updb there are no errors/warnings about any field

    Config export still has no changes

  • ivnish Kazakhstan

    We don't have any changes in configs because Image Storage ALREADY has display property in config (extended from File)

  • ivnish Kazakhstan

    @smustgrave do we need upgrade path tests if config doesn't change?

  • Status changed to Needs review 8 months ago
  • 🇺🇸United States smustgrave

    I definitely seemed to get config changes after applying the MR. Not from the update hook but from just resaving a field form.

  • ivnish Kazakhstan

    @smustgrave you are right, but config updated "default image uuid". It is not my patch issue. I installed clean Drupal instance, applied a patch and exported configs. I re-saved the article image field form and exported configs again. Then I compared configs.

    See screenshots

  • 🇺🇸United States smustgrave

    Did you try

    Fresh install
    Export config
    Apply patch
    Save field
    Export again?

  • ivnish Kazakhstan

    Yes. The result in #48

  • 🇺🇸United States smustgrave

    Will leave it for someone else to review

  • 🇮🇳India prashant.c Dharamshala

    @smustgrave in #47 you mean resaving the field by checking the checkbox or without any changes?

    • I tested it and on just resaving the image field there are no config changes in my case either.
    • By checking the checkbox, it will have a config change as the value is changing to TRUE
      display_default: true
  • 🇧🇾Belarus krakenbite

    Works fine

  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Pipeline finished with Failed
    6 months ago
    #312177
  • Pipeline finished with Success
    6 months ago
    #312184
  • ivnish Kazakhstan

    #54 issue fixed

  • Status changed to RTBC 4 months ago
  • 🇬🇧United Kingdom longwave UK

    It seems this was a deliberate choice at some point, from ImageItem::isDisplayed():

        // Image items do not have per-item visibility settings.
    

    This was added in #2090619: Move file visibility check to the FileItem class but there was no discussion that I can find as to why image items should not have this setting.

    However, I'm not really sure how useful this feature is. Aren't images meant to be displayed?

  • 🇧🇾Belarus krakenbite

    However, I'm not really sure how useful this feature is. Aren't images meant to be displayed?

    Yes! This is useful feature for some sites. I'm using it on my Drupal 6 projects and want to use on Drupal 10+ after migration

  • 🇧🇷Brazil pfeiffer

    I created a patch file with the diff of the PR to be more secure to use as a patch

  • 🇧🇷Brazil pfeiffer

    I tested the PR in a Drupal 11.1.0 and now I have the option for enabling the display control done by each node.

    Everything is working and no errors were logged, nice work!

    Editing a node:

    Editing the field:

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Left some comments on the MR

  • ivnish Kazakhstan

    @larowlan these tests are tests from File module (with some small changes). They working fine there and here :) Do we really need to modify it?

  • 🇺🇸United States dillix

    @longwave @larowlan this cool feature and for some reason it was removed from Image module, although the module File has it (looks like regression)

  • Status changed to Needs work about 1 month ago
  • 🇸🇰Slovakia Letha

    Hi, I tried applying the patch, but update.php didn't run successfully even after multiple attempts, without displaying any specific error.

    Is there a reason why it is placed in post_update instead of as an update in the install file? (I tried moving it to the install file, and it seems that the update.php ran fine.)

  • ivnish Kazakhstan

    Hi @letha post_update is a requirement of drupal core

    Do you have any errors in drupal log ?

  • 🇸🇰Slovakia Letha

    Oh, good to know, thanks :)

    Regarding the log, I only see an error that appears when I click on "Continue to the error page" :

    TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in C:\xampp83\htdocs\unipo\core\lib\Drupal\Component\Render\FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 431 of C:\xampp83\htdocs\unipo\core\lib\Drupal\Component\Utility\Html.php)

    #0 C:\xampp83\htdocs\unipo\core\lib\Drupal\Component\Render\FormattableMarkup.php(238): Drupal\Component\Utility\Html::escape(NULL)
    #1 C:\xampp83\htdocs\unipo\core\lib\Drupal\Component\Render\FormattableMarkup.php(187): Drupal\Component\Render\FormattableMarkup::placeholderEscape(NULL)
    #2 C:\xampp83\htdocs\unipo\core\lib\Drupal\Core\StringTranslation\TranslatableMarkup.php(195): Drupal\Component\Render\FormattableMarkup::placeholderFormat('The update proc...', Array)
    #3 C:\xampp83\htdocs\unipo\core\lib\Drupal\Component\Utility\ToStringTrait.php(15): Drupal\Core\StringTranslation\TranslatableMarkup->render()
    #4 C:\xampp83\htdocs\unipo\core\modules\system\src\Controller\DbUpdateController.php(440): Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
    #5 C:\xampp83\htdocs\unipo\core\modules\system\src\Controller\DbUpdateController.php(193): Drupal\system\Controller\DbUpdateController->results(Object(Symfony\Component\HttpFoundation\Request))
    #6 [internal function]: Drupal\system\Controller\DbUpdateController->handle('results', Object(Symfony\Component\HttpFoundation\Request))
    #7 C:\xampp83\htdocs\unipo\core\lib\Drupal\Core\Update\UpdateKernel.php(115): call_user_func_array(Array, Array)
    #8 C:\xampp83\htdocs\unipo\core\lib\Drupal\Core\Update\UpdateKernel.php(76): Drupal\Core\Update\UpdateKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request))
    #9 C:\xampp83\htdocs\unipo\update.php(27): Drupal\Core\Update\UpdateKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #10 {main}

    Warning: Undefined array key 1 in Drupal\system\Controller\DbUpdateController->results() (line 437 of C:\xampp83\htdocs\unipo\core\modules\system\src\Controller\DbUpdateController.php)

    #0 C:\xampp83\htdocs\unipo\core\includes\bootstrap.inc(108): _drupal_error_handler_real(2, 'Undefined array...', 'C:\\xampp83\\htdo...', 437)
    #1 C:\xampp83\htdocs\unipo\core\modules\system\src\Controller\DbUpdateController.php(437): _drupal_error_handler(2, 'Undefined array...', 'C:\\xampp83\\htdo...', 437)
    #2 C:\xampp83\htdocs\unipo\core\modules\system\src\Controller\DbUpdateController.php(193): Drupal\system\Controller\DbUpdateController->results(Object(Symfony\Component\HttpFoundation\Request))
    #3 [internal function]: Drupal\system\Controller\DbUpdateController->handle('results', Object(Symfony\Component\HttpFoundation\Request))
    #4 C:\xampp83\htdocs\unipo\core\lib\Drupal\Core\Update\UpdateKernel.php(115): call_user_func_array(Array, Array)
    #5 C:\xampp83\htdocs\unipo\core\lib\Drupal\Core\Update\UpdateKernel.php(76): Drupal\Core\Update\UpdateKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request))
    #6 C:\xampp83\htdocs\unipo\update.php(27): Drupal\Core\Update\UpdateKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #7 {main}

    Nothing else really. Update.php ends with "An unrecoverable error has occurred." and "An AJAX HTTP request terminated abnormally. " but nothing in browser's developer console or any other information that could provide a clue.

  • ivnish Kazakhstan

    Could you try the patch on clean drupal instance?

  • 🇸🇰Slovakia Letha

    Found the problem! It was caused by PHP 8.3 and the deprecated assert.active directive ( https://www.drupal.org/project/drupal/issues/3398033 📌 Remove mentions of assert.active from .htaccess Needs work ). Sorry for the confusion.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    This is actually causing a bug in experience builder because the default value set in the file widget is drawn from the field setting but ImageItem doesn't correctly change the default 📌 Media Library dialogs triggered from page data do not have buttons yet Active

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
Production build 0.71.5 2024