Skip to content
Snippets Groups Projects
Commit 1f1e6b7d authored by micha.jakubowski's avatar micha.jakubowski Committed by Claudiu Cristea
Browse files

ISAICP-9407: Refactor

parent a6b36505
No related branches found
No related tags found
1 merge request!210Patch release 2.2.1
Showing
with 45 additions and 147 deletions
......@@ -4,61 +4,21 @@
namespace Drupal\eu_oss_catalogue\Attribute;
use Attribute;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines a code hosting platform plugin.
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[\Attribute(\Attribute::TARGET_CLASS)]
class EuOssCatalogueHostingPlatform extends Plugin {
/**
* The plugin ID.
*/
public string $id;
/**
* The label of the plugin.
*
* This property is translatable.
*/
public Translation $label;
/**
* The code hosting platform base URL.
*
* Some plugins have non-configurable base URL (e.g. GitHub). They can provide
* the base URL in the annotation.
*/
public ?string $baseUrl = NULL;
/**
* API detection weight.
*
* The API guesser service calls each code hosting platform plugin in order to
* determine the platform handling a certain URL, until one of them knows to
* handle that URL. The order in which the plugins are queried is important.
* For instance, the `github` and `gitalb_com` plugins are cheap and their
* detection algorithm is trivial, thus they should be called first.
*
* The priority is a signed integer, with a Drupal weight-like logic: a lower
* integer means a higher priority. This definition entry is optional, and
* defaults to 0.
*
* @see \Drupal\eu_oss_catalogue\ApiGuesser
*/
public int $weight = 0;
/**
* {@inheritdoc}
*/
public function __construct(string $id, Translation $label, ?string $baseUrl, int $weight) {
$this->id = $id;
$this->label = $label;
$this->baseUrl = $baseUrl;
$this->weight = $weight;
}
public function __construct(
public readonly string $id,
public readonly TranslatableMarkup|string $label,
public readonly ?string $baseUrl = NULL,
public readonly int $weight = 0,
public readonly ?string $deriver = NULL,
) {}
}
......@@ -4,34 +4,19 @@
namespace Drupal\eu_oss_catalogue\Attribute;
use Attribute;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines a parser plugin.
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[\Attribute(\Attribute::TARGET_CLASS)]
class EuOssCatalogueParser extends Plugin {
/**
* The plugin ID.
*/
public string $id;
/**
* The label of the plugin.
*
* This property is translatable.
*/
public Translation $label;
/**
* {@inheritdoc}
*/
public function __construct(string $id, Translation $label) {
$this->id = $id;
$this->label = $label;
}
public function __construct(
public readonly string $id,
public readonly TranslatableMarkup|string $label,
public readonly ?string $deriver = NULL,
) {}
}
......@@ -4,54 +4,22 @@
namespace Drupal\eu_oss_catalogue\Attribute;
use Attribute;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines a EU OSS Catalogue provider.
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[\Attribute(\Attribute::TARGET_CLASS)]
class EuOssCatalogueProvider extends Plugin {
/**
* The plugin ID.
*/
public string $id;
/**
* The label of the plugin.
*
* This property is translatable.
*/
public Translation $label;
/**
* The parser used to convert data.
*/
public string $parser;
/**
* A short description of the provider plugin.
*
* This property is translatable.
*/
public ?Translation $description = NULL;
/**
* The config entity type ID that configures this plugin, if any.
*/
public ?string $configuredBy = NULL;
/**
* {@inheritdoc}
*/
public function __construct(string $id, Translation $label, string $parser, ?Translation $description, ?string $configuredBy) {
$this->id = $id;
$this->label = $label;
$this->parser = $parser;
$this->description = $description;
$this->configuredBy = $configuredBy;
}
public function __construct(
public readonly string $id,
public readonly TranslatableMarkup|string $label,
public readonly string $description,
public readonly string $parser,
public readonly ?string $deriver = NULL,
public readonly ?string $configuredBy = NULL,
) {}
}
......@@ -4,34 +4,19 @@
namespace Drupal\eu_oss_catalogue\Attribute;
use Attribute;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines a value resolver plugin.
*/
#[Attribute(Attribute::TARGET_CLASS)]
#[\Attribute(\Attribute::TARGET_CLASS)]
class EuOssCatalogueResolver extends Plugin {
/**
* The plugin ID.
*/
public string $id;
/**
* The label of the plugin.
*
* This property is translatable.
*/
public Translation $label;
/**
* {@inheritdoc}
*/
public function __construct(string $id, Translation $label) {
$this->id = $id;
$this->label = $label;
}
public function __construct(
public readonly string $id,
public readonly TranslatableMarkup|string $label,
public readonly ?string $deriver = NULL,
) {}
}
......@@ -151,7 +151,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
/**
* {@inheritdoc}
*/
public function getLabel(): TranslatableMarkup {
public function getLabel(): TranslatableMarkup|string {
return $this->pluginDefinition['label'];
}
......
......@@ -36,7 +36,7 @@ public function getProjects(array $requestedFiles = []): iterable;
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The label.
*/
public function getLabel(): TranslatableMarkup;
public function getLabel(): TranslatableMarkup|string;
/**
* Determines whether the plugin can parse the provided git URL.
......
......@@ -28,7 +28,7 @@ class HostingPlatformConfigForm extends EntityForm {
use AjaxFormHelperTrait;
public function __construct(
protected readonly EuOssCataloguePluginManagerInterface $platformManager,
protected EuOssCataloguePluginManagerInterface $platformManager,
) {}
/**
......
......@@ -194,7 +194,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
/**
* {@inheritdoc}
*/
public function getLabel(): TranslatableMarkup {
public function getLabel(): TranslatableMarkup|string {
return $this->pluginDefinition['label'];
}
......
......@@ -21,7 +21,7 @@
/**
* Developers Italia provider.
*/
#[EuOssCatalogueProvider(id: "developers_italia", label: "Developers Italia", parser: "publiccode_yml", description: "Italian National OSS Catalogue, by https://developers.italia.it website.")]
#[EuOssCatalogueProvider(id: "developers_italia", label: "Developers Italia", description: "Italian National OSS Catalogue, by https://developers.italia.it website.", parser: "publiccode_yml")]
class DevelopersItalia extends EuOssCatalogueProviderPluginBase {
/**
......
......@@ -19,7 +19,7 @@
/**
* Dutch catalogue provider.
*/
#[EuOssCatalogueProvider(id: "dutch_catalogue", label: "Developer Overheid", parser: "publiccode_yml", description: "Dutch National OSS Catalogue, by https://developer.overheid.nl website.")]
#[EuOssCatalogueProvider(id: "dutch_catalogue", label: "Developer Overheid", description: "Dutch National OSS Catalogue, by https://developer.overheid.nl website.", parser: "publiccode_yml")]
class DutchCatalogue extends EuOssCatalogueProviderPluginBase {
/**
......
......@@ -19,7 +19,7 @@
/**
* French catalogue provider.
*/
#[EuOssCatalogueProvider(id: "awesome_code_gouv_fr", label: "Awesome CodeGouvFr", parser: "publiccode_yml", description:"French National OSS Catalogue, by https://code.gouv.fr/fr/awesome/ website.")]
#[EuOssCatalogueProvider(id: "awesome_code_gouv_fr", label: "Awesome CodeGouvFr", description:"French National OSS Catalogue, by https://code.gouv.fr/fr/awesome/ website.", parser: "publiccode_yml")]
class FrenchCatalogue extends EuOssCatalogueProviderPluginBase {
/**
......
......@@ -20,7 +20,7 @@
/**
* Code hosting platform provider plugin.
*/
#[EuOssCatalogueProvider(id: "hosting_platform", label: "Hosting platform", parser: "publiccode_yml", description: "Code hosting platform", configuredBy: "hosting_platform")]
#[EuOssCatalogueProvider(id: "hosting_platform", label: "Hosting platform", description: "Code hosting platform", parser: "publiccode_yml", deriver: '\Drupal\eu_oss_catalogue\Plugin\eu_oss_catalogue\Deriver\HostingPlatformDeriver', configuredBy: "hosting_platform")]
class HostingPlatform extends EuOssCatalogueProviderPluginBase implements ConfigurableInterface {
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment