You are here

trait SchemaIdReferenceTrait in Schema.org Metatag 7

Schema.org Id Reference pivot trait.

Hierarchy

File

src/SchemaIdReferenceTrait.php, line 6

View source
trait SchemaIdReferenceTrait {
  use SchemaPivotTrait;

  /**
   * Return the SchemaMetatagManager.
   *
   * @return \Drupal\schema_metatag\SchemaMetatagManager
   *   The Schema Metatag Manager service.
   */
  protected abstract function schemaMetatagManager();

  /**
   * The form element.
   */
  public function idForm($input_values) {
    $input_values += $this
      ->schemaMetatagManager()
      ->defaultInputValues();
    $value = $input_values['value'];

    // Get the id for the nested @type element.
    $selector = ':input[name="' . $input_values['visibility_selector'] . '[@id]"]';
    $visibility = [
      'invisible' => [
        $selector => [
          'value' => '',
        ],
      ],
    ];
    $selector2 = $this
      ->schemaMetatagManager()
      ->altSelector($selector);
    $visibility2 = [
      'invisible' => [
        $selector2 => [
          'value' => '',
        ],
      ],
    ];
    $visibility['invisible'] = [
      $visibility['invisible'],
      $visibility2['invisible'],
    ];
    $form['#type'] = 'fieldset';
    $form['#title'] = $input_values['title'];
    $form['#description'] = $input_values['description'];
    $form['#tree'] = TRUE;

    // Add a pivot option to the form.
    $form['pivot'] = $this
      ->pivotForm($value);
    $form['pivot']['#states'] = $visibility;
    $form['@id'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('@id'),
      '#default_value' => !empty($value['@id']) ? $value['@id'] : '',
      '#maxlength' => 255,
      '#required' => $input_values['#required'],
      '#description' => $this
        ->t("Globally unique @id of the related node, usually a url, used to to link other properties to this object."),
    ];
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SchemaIdReferenceTrait::idForm public function The form element.
SchemaIdReferenceTrait::schemaMetatagManager abstract protected function Return the SchemaMetatagManager.
SchemaPivotTrait::pivotForm public function The form element.