Commit 77b06199 authored by Marco's avatar Marco
Browse files

Issue #3170475 by karishmaamin: drupal 9 compatibility fix and some smaller other fixes by marcoka.

parent af91bbc6
Loading
Loading
Loading
Loading
+52 −1
Original line number Diff line number Diff line
Body Inject (Content/Ad Injector)
How to use
-----------
1.) Create a block you want to insert into a node
2.) Create a profile and select the block, node type and conditions

What it does
--------------
Conditions:
- Checks if a Text has "more than/exactly/less than" x Parapgraphs
- AND/OR
- Checks if a Text has "more than/exactly/less than" Chars

- Then it inserts a block by actions, currently 3 avaliable:
  1 Offset to the middle position
  2 Insert the block after a number of paragraphs.
  3 Insert the block after a number of charcters.

ONLY set one value for the three above!

Info for the insert logic with characters
--------------------------
- Check char count and add after closest paragraph
- For character insertion. we can not insert after like 300 characters
- Because that could lead to insertion in the middle of a table or other weird places. So we use the closest paragraph

Problems
------------
-Plain HTML inserted?
Check the Textformat of you Adblock and set it to a custom textformat(create one) and disable all filters! Any filters! I advise creatin ga dedicated format because media filters etc. will mess up google adsense code for example somehow.
There is also still a problem where CKEditor doesn like EMPTY tags, so i added a &nbsp; inside the <ins> tag. It will result in creating <br> tags and output the html as plaintext...wtf.
Suggestions welcome.


Developer Info, Docs
-----------------
The Form for managing profiles is copied over from the "linkit" module and modified. Helped a lot, thank you.
This is relatively complex stuff, because of the split into multiple files and sensitive annotations.
If you want to understand it i suggest you read "Drupal 8 Development Cookbok" around pages 270!

Infos
https://www.drupal.org/docs/drupal-apis/configuration-api/creating-a-configuration-entity-type
https://drupalsun.com/ben/2015/05/08/creating-custom-config-entities-drupal-8
https://antistatique.net/en/we/blog/2018/05/01/drupal-8-how-to-translate-the-config-api
Drupal console can create a config entity!

Entity Blocks Infos
https://enzo.weknowinc.com/articles/2015/11/21/how-to-manipulate-an-entityblock-programmatically-in-drupal-8
https://www.drupal.org/node/2418529
https://www.webomelette.com/drupal-8-custom-data-configuration-entities-using-thirdpartysettingsinterface
some examples: https://gist.github.com/WengerK/5c7f3df9aa5c27a95cd8a29b72b28a19

+1 −0
Original line number Diff line number Diff line
@@ -4,3 +4,4 @@ package: Custom
type: module
core: 8.x
configure: entity.body_inject_profile.collection
core_version_requirement: ^8 || ^9
+0 −5
Original line number Diff line number Diff line
<?php


use Drupal\Core\Render\Markup;
/**
 * @file
@@ -8,9 +7,6 @@ use Drupal\Core\Render\Markup;
 */





/**
 * Implements hook_entity_view().
 * https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!entity.api.php/function/hook_entity_view/8.9.x
@@ -87,7 +83,6 @@ use Drupal\Core\Render\Markup;
//ideas
//https://www.drupal.org/project/drupal/issues/2626224


/**
* Implements hook_entity_view_alter().
 * https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!entity.api.php/function/hook_entity_view_alter/8.9.x
+7 −1
Original line number Diff line number Diff line
@@ -61,7 +61,13 @@ abstract class FormBase extends EntityForm {

    //block we want to inject
    $block_ref = $this->entity->getBlock();
    if(!empty($block_ref)) {
      $entity_block =  BlockContent::load($block_ref);
    }
    else {
      $entity_block = '';
    }

    //possible target_type
    //https://drupal.stackexchange.com/questions/208143/what-is-target-type-in-entityautocomplete
    $form['block_reference'] = [