View source
<?php
declare (strict_types=1);
namespace Drupal\swagger_ui_formatter\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SwaggerUILinkFormatter extends FormatterBase implements ContainerFactoryPluginInterface {
use SwaggerUIFormatterTrait;
public function __construct(string $plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, string $label, string $view_mode, array $third_party_settings, TranslationInterface $string_translation) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->stringTranslation = $string_translation;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], $container
->get('string_translation'));
}
public static function defaultSettings() {
$settings = parent::defaultSettings();
static::addDefaultSettings($settings);
return $settings;
}
public function settingsSummary() {
$summary = parent::settingsSummary();
$this
->addSettingsSummary($summary, $this);
return $summary;
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$this
->alterSettingsForm($form, $form_state, $this, $this->fieldDefinition);
return $form;
}
protected function getSwaggerFileUrlFromField(FieldItemInterface $field_item, array $context = []) {
return $field_item
->getUrl()
->toString();
}
public function viewElements(FieldItemListInterface $items, $langcode) {
return $this
->buildRenderArray($items, $this, $this->fieldDefinition, [
'lang_code' => $langcode,
]);
}
}