AdminFormFactory.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @package Grav\Plugin\Admin
  4. *
  5. * @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. declare(strict_types=1);
  9. namespace Grav\Plugin\Admin;
  10. use Grav\Common\Grav;
  11. use Grav\Common\Page\Interfaces\PageInterface;
  12. use Grav\Common\Page\Page;
  13. use Grav\Framework\Form\Interfaces\FormFactoryInterface;
  14. use Grav\Framework\Form\Interfaces\FormInterface;
  15. /**
  16. * Class FlexFormFactory
  17. * @package Grav\Plugin\FlexObjects
  18. */
  19. class AdminFormFactory implements FormFactoryInterface
  20. {
  21. /**
  22. * @param Page $page
  23. * @param string $name
  24. * @param array $form
  25. * @return FormInterface|null
  26. */
  27. public function createPageForm(Page $page, string $name, array $form): ?FormInterface
  28. {
  29. return $this->createFormForPage($page, $name, $form);
  30. }
  31. /**
  32. * @param PageInterface $page
  33. * @param string $name
  34. * @param array $form
  35. * @return FormInterface|null
  36. */
  37. public function createFormForPage(PageInterface $page, string $name, array $form): ?FormInterface
  38. {
  39. /** @var Admin|null $admin */
  40. $admin = Grav::instance()['admin'] ?? null;
  41. $object = $admin->form ?? null;
  42. return $object && $object->getName() === $name ? $object : null;
  43. }
  44. }