PluginWithFormsTrait.php 618 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace Drupal\Core\Plugin;
  3. /**
  4. * Provides a trait with typical behavior for plugins which have forms.
  5. */
  6. trait PluginWithFormsTrait {
  7. /**
  8. * {@inheritdoc}
  9. */
  10. public function getFormClass($operation) {
  11. if (isset($this->getPluginDefinition()['forms'][$operation])) {
  12. return $this->getPluginDefinition()['forms'][$operation];
  13. }
  14. elseif ($operation === 'configure' && $this instanceof PluginFormInterface) {
  15. return static::class;
  16. }
  17. }
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function hasFormClass($operation) {
  22. return !empty($this->getFormClass($operation));
  23. }
  24. }