This lightweight module is a kind of replacement of Insert module for Drupal 8. It allows you to manually insert images right into the text fields.

Unlike Insert, this module obliges you to use pseudo-tokens like [image:DELTA:STYLE], that will be replaced with themed images when viewing the entity. Here DELTA is the index (starting from 0) of the image being inserted, and STYLE is the name of image style (STYLE may be omitted; in this case default image will be shown). For example, here is a valid token:

[image:0:thumbnail]

Usage example

1. Manually add pseudo-tokens to text:
Add pseudo-tokens to text

2. See themed images on the site:
See themed images

Configuration

This module provides a text filter, which should be configured before using:

  1. After installation, go to http://YOURSITE/admin/config/content/formats and click Configure for text format you want to set up.
  2. On the text format configure screen, under Enabled filters section, check Insert Images option.
  3. Below, under Filter settings section, choose Insert Images tab and specify name of the field that contains images you want to insert (for example, field_inline_images).

Configuration screen:
Enable and configure filter

Token Filter module provides much more control on what you have in your text fields. It's a much more general solution, but less convenient if you just want to quickly insert (themed) images.

Entity Embed module is much more general and powerful solution providing similar result under certain conditions. But it is designed to be used with CKEditor and allows less theming flexibility.

Developers notes

Images being inserted can be easily themed using insert_image theme. Override default insert-image.html.twig template (which is just shows <img> tag) if you need.

Following template suggestions are supported out of the box:

insert-image--ENTITY_TYPE.html.twig
insert-image--ENTITY_TYPE--ENTITY_BUNDLE.html.twig
insert-image--ENTITY_TYPE--ENTITY_BUNDLE--VIEW_MODE.html.twig

For example, if you want to style images inserted in nodes of type "Article" when being viewed in "Full" view mode, use insert-image--node--article--full.html.twig template.

Project Page

https://www.drupal.org/sandbox/stanag/2828619

Git clone

git clone --branch 8.x-1.x https://git.drupal.org/sandbox/stan.ag/2828619.git insert_image
cd insert_image
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stan.ag created an issue. See original summary.

PA robot’s picture

Issue summary: View changes

Fixed the git clone URL in the issue summary for non-maintainer users.

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

icurk’s picture

Manual Review

Individual user account
[Yes: Follows] the guidelines for individual user accounts.
No duplication
[No: Causes] module entity_embed also allows you to add images into text editors. It also provides you with UI interface where you can select image style instead of writing id manually. It is a bit different workflow but in the end it gives you the same result.
Master Branch
[Yes: Follows] the guidelines for master branch.
Licensing
[Yes: Follows] the licensing requirements.
3rd party assets/code
[Yes: Follows] the guidelines for 3rd party assets/code.
README.txt/README.md
[Yes: Follows] the guidelines for in-project documentation and/or the README Template.
Code long/complex enough for review
[Yes: Follows] the guidelines for project length and complexity.
Secure code
Coding style & Drupal API usage
[No identified code issues.]

If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.

This review uses the Project Application Review Template.

I tested the module and all works as described above.

klausi’s picture

@icurk: looks like you forgot to change the status. Is this now RTBC after your review or are there application blockers left and this should be set to "needs work"?

icurk’s picture

Status: Needs review » Needs work
PA robot’s picture

Status: Needs work » Closed (won't fix)

Closing due to lack of activity. If you are still working on this application, you should fix all known problems and then set the status to "Needs review". (See also the project application workflow).

I'm a robot and this is an automated message from Project Applications Scraper.

stan.ag’s picture

Issue summary: View changes
stan.ag’s picture

Status: Closed (won't fix) » Needs review

Thanks for review icurk! I added Entity Embed as an alternative to the module description. It provides similar result under certain conditions. Meanwhile, it is designed to be used mostly by users, while my module is mostly for site builders and developers. This means:

  1. Entity Embed relies on CKEditor, while many people (like me) prefer to use code editors (like CodeMirror) instead of WYSIWYG ones. Of course, you may write <drupal-entity ...> tag manually, but no one will do this :)
  2. My module provides much more flexible theming capabilities. It declares own theme hook that may be used not to just insert images, but to insert any image-based snippet. If you want to have an ability to quickly insert some code that relies not only on image, but also on entity being viewed and current view mode, you won't do this easily with Entity Embed.

Personally for me this small module was preferable over other more general and powerful solutions on some my projects. Maybe it will be so for some other people :)

trangunghoa’s picture

FileSize
26.2 KB

Automated Review

https://pareview.sh/node/160

FILE: ...pos/pareviewsh/pareview_temp/src/Plugin/Filter/InsertImageFilter.php
--------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------
86 | ERROR | [x] Short array syntax must be used to define arrays
--------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------

Manual Review
Individual user account
No, I think you should add how to use in the README.md
No duplication
Yes
Master Branch
Yes
Licensing
No
3rd party assets/code
Yes
README.txt/README.md
Yes
Code long/complex enough for review
Yes
Secure code
[Yes: Meets the security requirements. / No: List of security issues identified.]
Coding style & Drupal API usage
When I setup in the admin/config/content/formats
and add an article, it's worked.
But I come back the admin/config/content/formats
change Field name from field_inline_images to field_inline_images1
it's show error.

Notice: Undefined index: exists in Drupal\Core\Render\Element\MachineName::validateMachineName() (line 251 of core\lib\Drupal\Core\Render\Element\MachineName.php).
Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in Drupal\Core\Render\Element\MachineName::validateMachineName() (line 252 of core\lib\Drupal\Core\Render\Element\MachineName.php).
apaderno’s picture

Priority: Normal » Critical

To the reviewers: Please change back the priority to Normal after doing a review.

sleitner’s picture

Priority: Critical » Normal
Status: Needs review » Needs work

Automated Review

Review of the 8.x-1.x branch (commit 6a888f2):

  • The insert_image.module does not implement hook_help(). See https://www.drupal.org/docs/develop/documenting-your-project/module-docu... .
  • Coder Sniffer has found some issues with your code (please check the Drupal coding standards).
    
    FILE: ...pal/pareviewsh/pareview_temp/src/Plugin/Filter/InsertImageFilter.php
    --------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------
     86 | ERROR | [x] Short array syntax must be used to define arrays
    --------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------
    
    Time: 520ms; Memory: 4Mb
    
  • DrupalPractice has found some issues with your code, but could be false positives.
    
    FILE: ...101/web/vendor/drupal/pareviewsh/pareview_temp/insert_image.info.yml
    --------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------
     7 | WARNING | All dependencies must be prefixed with the project name,
       |         | for example "drupal:"
    --------------------------------------------------------------------------
    
    Time: 236ms; Memory: 4Mb
    
  • No automated test cases were found, did you consider writing PHPUnit tests? This is not a requirement but encouraged for professional software development.

This automated report was generated with PAReview.sh, your friendly project application review script.

Manual Review

Individual user account
Yes: Follows the guidelines for individual user accounts.
No duplication
Yes: Does not cause module duplication and/or fragmentation.
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Yes: Follows the licensing requirements.
3rd party assets/code
Yes: Follows the guidelines for 3rd party assets/code.
README.txt/README.md
Yes: Follows the guidelines for in-project documentation and/or the README Template.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes: Meets the security requirements
Coding style & Drupal API usage
  1. (*) see pareview

The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.

If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.

This review uses the Project Application Review Template.

apaderno’s picture

Status: Needs work » Closed (won't fix)

If you are still working on this application, you should fix all known problems and set the status to Needs review. (See also the project application workflow.)
Please don't change status of this application if you aren't sure you have time to dedicate to this application, or it will be closed again as won't fix.

I am closing this application due to lack of activity.