-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from systopia/add-vertical-tabs
Add support for vertical tabs in remote forms
- Loading branch information
Showing
7 changed files
with
198 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2024 SYSTOPIA GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation in version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Civi\RemoteTools\Form\FormSpec; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
* | ||
* @api | ||
*/ | ||
class FormTab extends AbstractFormElementContainer implements FormElementInterface { | ||
|
||
public ?string $description; | ||
|
||
public function __construct(string $title, array $elements = [], ?string $description = NULL) { | ||
parent::__construct($title, $elements); | ||
$this->description = $description; | ||
} | ||
|
||
public function getType(): string { | ||
return 'tab'; | ||
} | ||
|
||
public function getDescription(): ?string { | ||
return $this->description; | ||
} | ||
|
||
public function setDescription(?string $description): self { | ||
$this->description = $description; | ||
|
||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2024 SYSTOPIA GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation in version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Civi\RemoteTools\Form\FormSpec; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
* | ||
* @extends AbstractFormElementContainer<FormTab> | ||
* | ||
* @api | ||
*/ | ||
class VerticalTabsContainer extends AbstractFormElementContainer implements FormElementInterface { | ||
|
||
public function __construct(array $elements = []) { | ||
parent::__construct('', $elements); | ||
} | ||
|
||
public function getType(): string { | ||
return 'vertical_tabs'; | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
Civi/RemoteTools/JsonForms/FormSpec/Factory/Layout/CategorizationFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2024 SYSTOPIA GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation in version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Civi\RemoteTools\JsonForms\FormSpec\Factory\Layout; | ||
|
||
use Civi\RemoteTools\Form\FormSpec\FormElementInterface; | ||
use Civi\RemoteTools\Form\FormSpec\VerticalTabsContainer; | ||
use Civi\RemoteTools\JsonForms\FormSpec\ElementUiSchemaFactoryInterface; | ||
use Civi\RemoteTools\JsonForms\FormSpec\Factory\AbstractConcreteElementUiSchemaFactory; | ||
use Civi\RemoteTools\JsonForms\JsonFormsElement; | ||
use Civi\RemoteTools\JsonForms\Layout\JsonFormsCategorization; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CategorizationFactory extends AbstractConcreteElementUiSchemaFactory { | ||
|
||
public function createSchema( | ||
FormElementInterface $element, | ||
ElementUiSchemaFactoryInterface $factory | ||
): JsonFormsElement { | ||
Assert::isInstanceOf($element, VerticalTabsContainer::class); | ||
/** @var \Civi\RemoteTools\Form\FormSpec\VerticalTabsContainer $element */ | ||
$elements = array_map([$factory, 'createSchema'], $element->getElements()); | ||
|
||
return new JsonFormsCategorization($elements); | ||
} | ||
|
||
public function supportsElement(FormElementInterface $element): bool { | ||
return $element instanceof VerticalTabsContainer; | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
Civi/RemoteTools/JsonForms/FormSpec/Factory/Layout/CategoryFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2024 SYSTOPIA GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation in version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Civi\RemoteTools\JsonForms\FormSpec\Factory\Layout; | ||
|
||
use Civi\RemoteTools\Form\FormSpec\FormElementInterface; | ||
use Civi\RemoteTools\Form\FormSpec\FormTab; | ||
use Civi\RemoteTools\JsonForms\FormSpec\ElementUiSchemaFactoryInterface; | ||
use Civi\RemoteTools\JsonForms\FormSpec\Factory\AbstractConcreteElementUiSchemaFactory; | ||
use Civi\RemoteTools\JsonForms\JsonFormsElement; | ||
use Civi\RemoteTools\JsonForms\Layout\JsonFormsCategory; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CategoryFactory extends AbstractConcreteElementUiSchemaFactory { | ||
|
||
public function createSchema( | ||
FormElementInterface $element, | ||
ElementUiSchemaFactoryInterface $factory | ||
): JsonFormsElement { | ||
Assert::isInstanceOf($element, FormTab::class); | ||
/** @var \Civi\RemoteTools\Form\FormSpec\FormTab $element */ | ||
$elements = array_map([$factory, 'createSchema'], $element->getElements()); | ||
|
||
return new JsonFormsCategory($element->getTitle(), $elements, $element->getDescription()); | ||
} | ||
|
||
public function supportsElement(FormElementInterface $element): bool { | ||
return $element instanceof FormTab; | ||
} | ||
|
||
} |