-
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.
Add support for internal links in forms
- Loading branch information
Dominic Tubach
committed
Aug 5, 2024
1 parent
a2e63d2
commit c5da605
Showing
2 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
Civi/RemoteTools/Form/FormSpec/Other/InternalLinkElement.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,105 @@ | ||
<?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\Custom; | ||
|
||
use Civi\RemoteTools\Form\FormSpec\FormElementInterface; | ||
|
||
/** | ||
* Displays a link to a CiviCRM resource. The URL is not exposed to users, but | ||
* the remote system acts as proxy. | ||
*/ | ||
final class InternalLinkElement implements FormElementInterface { | ||
|
||
private string $url; | ||
|
||
private string $label; | ||
|
||
private ?string $description; | ||
|
||
private ?string $filename; | ||
|
||
/** | ||
* @param string|null $filename | ||
* If given, this filename will be appended to the URL to give the users a | ||
* more convenient URL. | ||
*/ | ||
public function __construct(string $url, string $label, ?string $description = NULL, ?string $filename = NULL) { | ||
$this->url = $url; | ||
$this->label = $label; | ||
$this->description = $description; | ||
$this->filename = $filename; | ||
} | ||
|
||
public function getType(): string { | ||
return 'internalLink'; | ||
} | ||
|
||
public function getUrl(): string { | ||
return $this->url; | ||
} | ||
|
||
public function setUrl(string $url): self { | ||
$this->url = $url; | ||
|
||
return $this; | ||
} | ||
|
||
public function getLabel(): string { | ||
return $this->label; | ||
} | ||
|
||
public function setLabel(string $label): self { | ||
$this->label = $label; | ||
|
||
return $this; | ||
} | ||
|
||
public function getDescription(): ?string { | ||
return $this->description; | ||
} | ||
|
||
public function setDescription(?string $description): self { | ||
$this->description = $description; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
* If set, this filename will be appended to the URL to give the users a | ||
* more convenient URL. | ||
*/ | ||
public function getFilename(): ?string { | ||
return $this->filename; | ||
} | ||
|
||
/** | ||
* @param string|null $filename | ||
* If given, this filename will be appended to the URL to give the users a | ||
* more convenient URL. | ||
*/ | ||
public function setFilename(?string $filename): self { | ||
$this->filename = $filename; | ||
|
||
return $this; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
Civi/RemoteTools/JsonForms/FormSpec/Factory/Other/InternalLinkFactory.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,52 @@ | ||
<?php | ||
/* | ||
* Copyright (C) 2023 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\Custom; | ||
|
||
use Civi\RemoteTools\Form\FormSpec\Custom\InternalLinkElement; | ||
use Civi\RemoteTools\Form\FormSpec\FormElementInterface; | ||
use Civi\RemoteTools\JsonForms\FormSpec\ElementUiSchemaFactoryInterface; | ||
use Civi\RemoteTools\JsonForms\FormSpec\Factory\AbstractConcreteElementUiSchemaFactory; | ||
use Civi\RemoteTools\JsonForms\JsonFormsElement; | ||
use Webmozart\Assert\Assert; | ||
|
||
/** | ||
* Creates a custom JSON Forms element for internal links. | ||
*/ | ||
final class InternalLinkFactory extends AbstractConcreteElementUiSchemaFactory { | ||
|
||
public function createSchema( | ||
FormElementInterface $element, | ||
ElementUiSchemaFactoryInterface $factory | ||
): JsonFormsElement { | ||
Assert::isInstanceOf($element, InternalLinkElement::class); | ||
/** @var \Civi\RemoteTools\Form\FormSpec\Custom\InternalLinkElement $element */ | ||
return new JsonFormsElement('InternalLink', [ | ||
'url' => $element->getUrl(), | ||
'label' => $element->getLabel(), | ||
'description' => $element->getDescription(), | ||
'filename' => $element->getFilename(), | ||
]); | ||
} | ||
|
||
public function supportsElement(FormElementInterface $element): bool { | ||
return $element instanceof InternalLinkElement; | ||
} | ||
|
||
} |