Skip to content

GitRepositoryFormatterBase

Base formatter for data read from a repository's host.


  • Full name: \Drupal\git_field\Plugin\Field\FieldFormatter\GitRepositoryFormatterBase
  • Parent class: FormatterBase
  • This class is an Abstract class

Properties

api

The Git API service.

protected \Drupal\git_host\GitApi $api

Methods

create

{@inheritdoc}

public static create(\Symfony\Component\DependencyInjection\ContainerInterface $container, array $configuration, mixed $plugin_id, mixed $plugin_definition): static
  • This method is static. Parameters:
Parameter Type Description
$container \Symfony\Component\DependencyInjection\ContainerInterface
$configuration array
$plugin_id mixed
$plugin_definition mixed

getSupportedProviders

Gets the providers this formatter works with.

protected getSupportedProviders(): string[]

Return Value:

Git provider plugin IDs, or an empty array for every provider.


viewItem

Builds the output for one repository.

protected viewItem(string $host, string $repository): array
  • This method is abstract. Parameters:
Parameter Type Description
$host string
The repository's host, such as github.com.
$repository string
The repository's path on the host, such as owner/name.

Return Value:

A render array.

Throws:

If the data can't be read. The base class shows the error instead. - Exception


viewElements

{@inheritdoc}

public viewElements(\Drupal\Core\Field\FieldItemListInterface $items, mixed $langcode): array

Parameters:

Parameter Type Description
$items \Drupal\Core\Field\FieldItemListInterface
$langcode mixed

view

{@inheritdoc}

public view(\Drupal\Core\Field\FieldItemListInterface $items, mixed $langcode = null): array

Parameters:

Parameter Type Description
$items \Drupal\Core\Field\FieldItemListInterface
$langcode mixed

errorElement

Builds the output for an error from a host's API.

protected errorElement(\Throwable $exception): array

Parameters:

Parameter Type Description
$exception \Throwable
The exception from the request or from reading its data.

Return Value:

A render array with the host's error message, as plain text.


getFileData

Gets the data of a JSON or YAML file in a repository.

protected getFileData(string $host, string $repository, string $path, string $ref = ''): array

Parameters:

Parameter Type Description
$host string
The repository's host.
$repository string
The repository's path on the host, such as owner/name.
$path string
The file's path in the repository.
$ref string
(optional) A branch, tag or commit. Defaults to the default branch.

Return Value:

The file's data.