Faq Field Pivot for Schema

Created on 8 June 2022, almost 3 years ago
Updated 11 February 2023, over 2 years ago

Hi, please would you be so kind to guide me.

I'm using multiple faq field to create rich results for schema faqpage.

In schema, as follows:

Field name= [node:field_faq]
Text= [node:field_faq:question]
Answer= [node:field_faq:answer]

Works great as a single faq, but enabling 'pivot' for multiple fields, the schema disappears and not validating.

Most appreciate any support.

πŸ’¬ Support request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡«πŸ‡·France liliplanet Cannes

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

Comments & Activities

Not all content is available!

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

  • Hello, yes the same thing happens to me too. But I have configured FAQField as a custom block and I get blank. If I put fixed text if it is shown.
    In pivot it always comes out empty (no fields).

    I have tried:
    [node:field_faq]
    [node:field_faq:answer]
    [node:field_faq:question]

    [block_content:field_faq:0]
    [block_content:field_faq:0:answer]
    [block_content:field_faq:0:question]

    But no results.

    Can you guide me?
    Thanks

  • πŸ‡¨πŸ‡΄Colombia jucedogi

    To @ReVija or anyone else wondering still.

    The latest version of schema_metatag does support this.

    You must take care of the multiple value separator that you must define in the settings page for the metatag module. Default is ",".

    From there you must select the "Pivot" option and assing the text value with the multiple options separated with the properly assigned separator character. Take care that the text values do not include said character.

    In my case tokens were defined as:

    - [node:field_faq:0:question];[node:field_faq:1:question];[node:field_faq:2:question];[node:field_faq:3:question]

    and

    - [node:field_faq:0:answer];[node:field_faq:1:answer];[node:field_faq:2:answer];[node:field_faq:3:answer]

  • πŸ‡ΊπŸ‡¦Ukraine oleksandr p. Lutsk

    oleksandr p. β†’ made their first commit to this issue’s fork.

  • πŸ‡ΊπŸ‡¦Ukraine oleksandr p. Lutsk

    oleksandr p. β†’ changed the visibility of the branch 3284608-faq-field-pivot to hidden.

  • πŸ‡ΊπŸ‡¦Ukraine oleksandr p. Lutsk

    I investigated this and a similar issue https://www.drupal.org/project/schema_metatag/issues/3341248 πŸ’¬ Faq Field Pivot for Schema Active , and can conclude that this issue is very specific, and schema logic generally works as designed.

    For a more correct FAQPage structure with the faq field, I use the following hook:

    /**
     * Changes the FAQPage structure for correct metatags schema implementation.
     *
     * Implements hook_metatags_attachments_alter().
     */
    function module_name_metatags_attachments_alter(array &$metatag_attachments) {
      $head_content = &$metatag_attachments['#attached']['html_head'];
      $qa_pages = [];
      foreach ($head_content as $head_key => $content) {
        if ($content[1] === 'schema_qa_page_type') {
          $qa_pages[] = $head_key;
        }
        if ($content[1] === 'schema_qa_page_main_entity_0') {
          $qa_pages[] = $head_key;
          $faq_schema = [];
          $node = \Drupal::routeMatch()->getParameter('node');
          if ($node instanceof NodeInterface && $node->hasField('field_faqs')) {
            $faq_content = $node->get('field_faqs')->getValue();
            if (!empty($faq_content)) {
              foreach ($faq_content as $key => $faq_item) {
                $faq_schema[$key] = [
                  '@type' => 'Question',
                  'name' => preg_replace("/\r|\n/", '', strip_tags($faq_item['question'])),
                  'text' => preg_replace("/\r|\n/", '', strip_tags($faq_item['question'])),
                  'acceptedAnswer' => [
                    '@type' => 'Answer',
                    'text' => preg_replace("/\r|\n/", '', strip_tags($faq_item['answer'])),
                  ],
                ];
              }
              $head_content[$head_key][0]['#attributes']['content'] = $faq_schema;
            }
            else {
              // Removes FAQPage metatags schema from the general list.
              foreach ($qa_pages as $page_key) {
                unset($head_content[$page_key]);
              }
            }
          }
        }
      }
    }

    And I need to mention that this solution, in my opinion, is a better way to solve this issue.

    Hope I helped someone with it.

  • πŸ‡¬πŸ‡·Greece denizserhat

    question: [node:field_faq:0:question],[node:field_faq:1:question],[node:field_faq:2:question],[node:field_faq:3:question],[node:field_faq:4:question]

    answer: [node:field_faq:0:answer],[node:field_faq:1:answer],[node:field_faq:2:answer],[node:field_faq:3:answer],[node:field_faq:4:answer]

    I filled in the fields as above. I have 5 questions and 5 answers, although the question fields work correctly, it places all 5 answers in the same order under each question. Pivot options are enabled. How can I fix this?

Production build 0.71.5 2024