google docs – Indent paragraph’s first line, without also indenting headings?

In a Google Doc, it’s well known how to set the paragraph style for “normal text” to indent the first line: in a normal text paragraph, view ruler, in ruler at left margin drag its tiny blue rectangle rightwards, format > styles > normal text > update to match.

But how can one do that without also indenting every other kind of paragraph, such as titles and headings? Must one turn off all those indents one at a time?

forms – How to add and associate Paragraphs to Media Library Images Programmatically

Good day everyone,

Our client wants to have this feature where he can upload/reuse multiple images for an article content type. This can be achieved using a Media Library, where I find it tricky is each images will have additional fields(Alt, Copyright, Description fields), I’ve tried adding the additional fields to the Image Media Type but once the node is saved, their value will be associated to the image’s metadata. The proper functionality should be is when the node is saved, the Alt and Description of the images should be associated to the node’s metadata because Images can be reusable to another node, and the values of Alt and Description varies to each node.

So I talked with someone who really knows a lot about Drupal. He suggested that I keep the Media Library, and create a Paragraph Type. I called it ‘Image Library Paragraphs’, this paragraph has Image, Alt, Copyright, and Description fields. This way the Paragraph can hold the id of the image, alt, description and the node’s ID. In theory, what we’re trying to do here is everytime the user uploads/select an image. We must find a way to associate that image and add corresponding paragraph for each of those images. So if the user uploads/selects 3 images. It will also automatically create 3 paragraphs for those images. We also would need to reconstruct the layout of the form to somehow “blend” the image and its corresponding paragraphs. And since the position of the images can be changed, we also need to somehow reposition its paragraph accordingly to the image.

It’s tricky and a lot of work, honestly it’s even beyond my Drupal skills. But any help to the right direction will truly be appreciated. I haven’t even tried creating a really complex custom module. But would really want to learn how this can be done. Thank you in advance.

In theory this is what it’s gonna look like
enter image description here

enter image description here

How to aggregate values from fields in Paragraphs based on value of another field in that same paragraph, and display in an aggregated Views table?

Hopefully my title makes sense…

I am setting up a Drupal 9 website for internal use as a financial reporting engine and a CRM. I am making use of the following modules:

  • Paragraphs
  • Views
  • Viewfield
  • View Fields View
  • Views Aggregator Plus

I have one Paragraph (Entity Reference) unlimited-value field on a paragraph type called “Project”. That field is called “Transactions”. It refers to a paragraph type called “Transaction”.

The “Transaction” paragraph type has the following fields:

  • Transaction Amount (decimal field))
  • Status (term reference field. Values are PAID and UNPAID)
  • Paid On (date field)
  • Year (a taxonomy entity reference field that contains pre-set years (2019, 2020, 2021, etc).

I have a content type called “Company”. It has the following fields:

  • Title
  • Project (a Paragraph/Entity Reference field)
  • Transaction Amount – Paid (a Viewfield)
  • Transaction Amount – Unpaid (a Viewfield)
    • These two Viewfields are of content type “Company”
      • One is filtered to the Transaction paragraph’s status “Paid”; the other is filtered to “Unpaid”.
    • They contain this field, which is SUMmed through Views Aggregation: (field_transactions: Paragraph) SUM(Paragraph: Transaction Amount)
    • They contain these relationships:
    field_projects_paragraph: Paragraph
    (field_projects_paragraph: Paragraph) field_transactions: Paragraph
    (field_projects_paragraph: Paragraph) field_transactions




    

The output displays the sum of the paid or unpaid transactions. For example, if a company has a project which has 3 PAID transactions of $100 each, this view will output “$300”. The intent is to display this value on the “Overview of Transactions” view, as described below:

Overview of Transactions view…

I have created a View of “Company” content of display format: “Table with Aggregation Options” that will display a table of the following columns:

  • Company Title
  • Total Transaction Amount (a SUM aggregation of all transaction “Transaction Amount” values.
  • Total Transaction Amount with status = PAID
  • Total Transaction Amount with status = UNPAID

The intent is to display an at-a-glance table of all Companies on the site, showing a line for each Company, that Company’s Total Transaction amount (which includes paid and unpaid), that company’s PAID total amount, and that company’s UNPAID total amount.

Further, the intent is to be able to filter this table based on the “Year” taxonomy term value from the Transaction paragraph type (filter it to only contain data that is tagged with “2020”, for example), or to filter it by date range using the “Paid On” value from the Transaction paragraph type (filter it to only contain data that contains a date value of 01/01/2020 – 01/03/2020, for example). The purpose is to be able to see all dollar amounts per company on a yearly, monthly, weekly, daily, or any other date range basis. For example: “display all company transaction data for Jan 1, 2020 through March 31, 20020, and then run that same report for that same time period in 2021.

To the View, I added the following settings:

Relationships:

    - field_projects_paragraph: Paragraph
    - (field_projects_paragraph: Paragraph) field_transactions: Paragraph

Filter Criteria:

    Content: Content type (= Company)
    (field_transactions: Paragraph) Paragraph: Year (exposed)
    (field_transactions: Paragraph) Paragraph: Paid On (exposed)

Fields:

    Content: ID (ID) (hidden)
    (field_transactions: Paragraph) Paragraph: ID (ID) (hidden)
    Content: Title (Title)
    (field_transactions: Paragraph) SUM(Paragraph: Transaction Amount) (Transaction Amount)
    Content: Transaction Amount - Paid (Transaction Amount - Paid) - This is one of the Views Field View fields from the Company content type
    Content: Transaction Amount - Unpaid (Transaction Amount - Unpaid) - This is one of the Views Field View fields from the Company content type

Format:Table with aggregation options

        ID: Apply Group Function: Group and Compress
        (field_transactions: Paragraph) Transaction Amount: Column Aggregation: Sum

    

My current end result is as follows:

  • Each Company has its only single line in the table.
  • The “Total
    Transaction Amount” field correctly sums the company’s total
    transactions (paid and unpaid), and the column successfully
    aggregated the total transactions of all Companies on the site.
  • The
    “Content: Transaction Amount – Paid (Transaction Amount – Paid)”
    field correctly displays the company’s total PAID transactions, but
    it does not adhere to the Year and Paid On filters. Additionally, the
    column will not SUM with the Table Aggregation settings at all.
  • The
    “Content: Transaction Amount – Unpaid (Transaction Amount – Paid)”
    field correctly displays the company’s total UNPAID transactions, but
    it does not adhere to the Year and Paid On filters. Additionally, the
    column will not SUM with the Table Aggregation settings at all.

How can I display each company’s Paid and Unpaid transaction totals in this Views aggregated table, and also make those two values subject to the Year and Paid On filters?

I am open to completely re-thinking the organization of the node types, data, etc.

google – For SEO, can the home page contain summary text about several categories with multiple paragraphs written on more specific pages?

Let me answer from Google’s perspective.

What are the rules in 2021 for writing text for SEO?

Perhaps the following Google recommendations can help:

Content and quality questions Does the content provide original

information, reporting, research or analysis? Does the content provide
a substantial, complete or comprehensive description of the topic?
Does the content provide insightful analysis or interesting
information that is beyond obvious? If the content draws on other
sources, does it avoid simply copying or rewriting those sources and
instead provide substantial additional value and originality? Does the
headline and/or page title provide a descriptive, helpful summary of
the content? Does the headline and/or page title avoid being
exaggerating or shocking in nature? Is this the sort of page you’d
want to bookmark, share with a friend, or recommend? Would you expect
to see this content in or referenced by a printed magazine,
encyclopedia or book?

Expertise questions Does the content present

information in a way that makes you want to trust it, such as clear
sourcing, evidence of the expertise involved, background about the
author or the site that publishes it, such as through links to an
author page or a site’s About page? If you researched the site
producing the content, would you come away with an impression that it
is well-trusted or widely-recognized as an authority on its topic? Is
this content written by an expert or enthusiast who demonstrably knows
the topic well? Is the content free from easily-verified factual
errors? Would you feel comfortable trusting this content for issues
relating to your money or your life?

Presentation and production questions

Is the content free from spelling or stylistic issues? Was
the content produced well, or does it appear sloppy or hastily
produced? Is the content mass-produced by or outsourced to a large
number of creators, or spread across a large network of sites, so that
individual pages or sites don’t get as much attention or care? Does
the content have an excessive amount of ads that distract from or
interfere with the main content? Does content display well for mobile
devices when viewed on them?

Comparative questions

Does the content provide substantial value when compared to other pages in search
results? Does the content seem to be serving the genuine interests of
visitors to the site or does it seem to exist solely by someone
attempting to guess what might rank well in search engines?

How much text is needed about a certain topic?

There are no explicit guidelines, requirements or guidelines for the size of the content.

How much should you repeat yourself? How does Google punish you if you
write too much of the same thing?

Check the guide Avoid creating duplicate content of Google.

An e-commerce platform has 5 shopping categories. Each category has
their own page with text. However on the front page they’ve chosen to
write paragraphs about each category. The text is a short summary but
not a copy-paste of the category pages. The text is accompanied by a
h2 tag.

Is that good practice? To have small texts about each category all
over the start page? Or should you just have a little generic
paragraph about the whole site at the beginning?

In my humble opinion, your second point does not exclude the possibility of existence for the first point. The content of the home page by default has info about the content entities of the entire website including product categories. It may be pertinent to remember here that all websites offering online payment are treated by Google as Your Money Or Your Life – YMYL. Therefore, it is quite important to indicate in the content of the website comprehensive information about the organization of an e-commerce business, including the points of the business registration certificate. It is also important to provide complete information about the customer service and the person responsible for this service. In the content of the home page (before the fold), you can specify a description with the specifics of e-commerce and set a text link to a page with full information about the business. The same applies to customer service.

8 – How to canonically delete Paragraphs?

Drupal 8, Paragraphs Version: 8.x-1.12, ERR Version: 8.x-1.8

I created a custom paragraph type. I then added a field on a node type that referenced that custom paragraph. Adding the paragraph and saving it in that nodes edit form works great. When I click ‘remove’ or, after, ‘confirm removal’ not only is it not removed from the database, no delete or pre-delete hooks are run. If the node edit form is reloaded, the paragraph is back with the values it had before ‘remove’ or ‘confirm removal’. If i remove and confirm removal and save the node, again, no delete or predelete hooks are run, but if the node edit form is reloaded, the paragraph appears removed. However, it still exists in the paragraphs_items_field_data table. If i just delete the entire node, the paragraph still exists in paragraphs_items_field_data.

What is the reason for this behavior? Is it because you could still restore an old revision of the node after deletion?

How do I canonically delete a Paragraph? Can it only be done programmatically?

8 – How to migrate content (fields and paragraphs) into another content type?

My problem is following:

Initial situation

At my Drupal 8 site I have a node content type (let’s calling it node content type A). node content type A has normal (core) fields included and also holds a field with paragraphs items.

Problem/proposed solution

Now I have to change my data model. Due to it’s not adviced to change node content type machine name in a Drupal 8 site, I should go another way:

  1. Clone the content type (would use Entity type clone module for this step). Let’s calling it node content type B
  2. Clone all already existing content of node content type A into new nodes of node content type B
  3. Modify each content/content type as needed by the requirements of the new data model.

Question

How can I perform step 2, especially with the existing paragraphs items?

Thanks in advance for help and/or alternative ways.

paragraphs – How do I create a block in a module that can be referenced via an entity reference field?

I’d like to be able to reference my programmed block as a field in a paragraphs.

I’ve

  • Generated a module with drupal console – drupal generate:module
  • Used the template for a block from the example module. Only has Plugin/Block/MyBlock.php

I create a new field in my paragraph

  • Field type Reference
  • choose other

How do I get the block to be able to be embedded in this way?

migration – Migrate field collection to paragraphs and split into multiple paragraphs

I’m migrating a Drupal 7 site with field collections to Drupal 8 paragraphs, but I’m having some issues setting up the migration.
In Drupal 7 I have a News content type with a field_news_items field collection field, which contains a lot of field. Based on the filled-in fields, I would like to create a paragraph or split them into multiple paragraphs during migration.

The field collection contains for example these fields:

  • field_title
  • field_text
  • field_quote
  • field_images
  • field_cta_link
  • field cta_image
  • field_video
  • field_attachments

If field_text is not empty, I should migrate to a text paragraph; if field_quote is not empty, I should migrate to a quote paragraph; if field_images is not empty, I should migrate to a gallery paragraph; and so on.

In the Drupal 7 site, in one field_collection item it’s possible almost all fields are filled in. So during the migration I should split them into multiple paragraph items, but they will share the same original item_id. Will this give issues?
I’m confused and it’s not clear on how to start with this.

On the Drupal 8 side, I have an Article content type with field_paragraphs.
I tried creating separate migrations for each combination, but it didn’t work.

What is best practice for migrating these field collections?

How to view all the matching paragraphs in the web page in the search engine?

Not all search tasks are easy, sometimes several keywords need to be used to describe, and many web pages are very long, so many times there is no desired content in the title and abstract, so you have to click in one by one and search again in the page. If there are many keywords, it will be very troublesome, which is unnecessary and repetitive.

Is there any way to directly display all the matching content in a web page? This saves the trouble of searching in the page and flipping around. The slightly reliable local search function has a list of search results, which can locate each matching place, or even directly view the context, such as visual studio code, PDF xchange editor, and filelocator But does a search engine like Google Bing have such a function?

If not, is there any other way to achieve it?

I know that sometimes search engines can provide highlighted services, but not all pages have them, and the efficiency of using them is still far behind that of listing the results directly. I went to Google to search for relevant keywords, but I didn’t find any more clues at present.

So I can only come here for help.

enter image description here

8 – How to create a form render element for a paragraphs field?

I have the following EntityForm and I want to add a entity_reference_revisions field for the paragraph entity with the allowed bundle type orga_structure.

I searched the web but haven’t found a hint to resolve this.

$form(‘target’) is the element I tried, but it isn’t rendered.

class AbsenceConfigForm extends EntityForm {

  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);

    $absence_config = $this->entity;
    $form('label') = (
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
      '#maxlength' => 255,
      '#default_value' => $absence_config->label(),
      '#description' => $this->t("Label for the Absence config."),
      '#required' => TRUE,
    );

    $form('id') = (
      '#type' => 'machine_name',
      '#default_value' => $absence_config->id(),
      '#machine_name' => (
        'exists' => 'Drupalks_absenceEntityAbsenceConfig::load',
      ),
      '#disabled' => !$absence_config->isNew(),
    );

    /* You will need additional form elements for your custom properties. */
    
    $form('target') = (
      '#type' => 'entity_reference_revisions',
      '#handler' => 'default:paragraph',
      '#handler_settings' => (
        'target_type' => (
          'orga_structure',
        ),
      ),
    );

    // $form('target') = BaseFieldDefinition::create('entity_reference_revisions')
    //   ->setLabel(t('Skill'))
    //   ->setDescription(t('The ID of the skill'))
    //   ->setRevisionable(TRUE)
    //   ->setSetting('handler', 'default:paragraph')
    //   ->setSetting('handler_settings', ('target_bundles' => ('orga_structure' => 'orga_structure')))
    //   ->setSetting('handler_settings', ('negate' => 0))
    //   ->setTranslatable(TRUE)
    //   ->setDisplayOptions('form', (
    //     'type' => 'entity_reference_autocomplete',
    //     'weight' => 5,
    //     'settings' => (
    //       'match_operator' => 'CONTAINS',
    //       'size' => '60',
    //       'autocomplete_type' => 'tags',
    //       'placeholder' => '',
    //     ),
    //   ))
    //   ->setDisplayConfigurable('form', TRUE);
    
    return $form;
  }

  public function save(array $form, FormStateInterface $form_state) {
    $absence_config = $this->entity;
    $status = $absence_config->save();

    switch ($status) {
      case SAVED_NEW:
        $this->messenger()->addMessage($this->t('Created the %label Absence config.', (
          '%label' => $absence_config->label(),
        )));
        break;

      default:
        $this->messenger()->addMessage($this->t('Saved the %label Absence config.', (
          '%label' => $absence_config->label(),
        )));
    }
    $form_state->setRedirectUrl($absence_config->toUrl('collection'));
  }

}

Update:
I would like to achieve that the fields specified in the paragraph are rendered in this form.