summaryrefslogtreecommitdiffstats
path: root/src/Plugin/ResourceFieldEnhancerBase.php
blob: fa053d667a6547ace596d67fa4b849d771d3f982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

namespace Drupal\jsonapi_extras\Plugin;

use Drupal\Core\Plugin\PluginBase;

/**
 * Common base class for resourceFieldEnhancer plugins.
 *
 * @see \Drupal\jsonapi_extras\Annotation\ResourceFieldEnhancer
 * @see \Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager
 * @see \Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerInterface
 * @see plugin_api
 *
 * @ingroup third_party
 */
abstract class ResourceFieldEnhancerBase extends PluginBase implements ResourceFieldEnhancerInterface {

  /**
   * Holds the plugin configuration.
   *
   * @var array
   */
  protected $configuration;

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    // TODO: This should have a dependency on the resource_config entity.
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration
      ? $this->configuration
      : $this->setConfiguration([]);
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = $configuration + $this->defaultConfiguration();
    return $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function getSettingsForm(array $resource_field_info) {
    return [];
  }

}