-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Remove code which is being migrated to a new TinyMCE module
- Loading branch information
1 parent
40c015c
commit d3eb6c1
Showing
12 changed files
with
266 additions
and
1,549 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Forms\HTMLEditor; | ||
|
||
use DOMAttr; | ||
|
||
class AttributeRule | ||
{ | ||
public string $name; | ||
|
||
public array $validValues = []; | ||
|
||
public ?string $defaultValue = null; | ||
|
||
public ?string $forcedValue = null; | ||
|
||
public bool $required = false; | ||
|
||
public function __construct(string $name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function attributeIsAllowed(DOMAttr $attribute): bool | ||
{ | ||
// If the rule has a set of valid values, check them to see if this attribute has one | ||
if (isset($this->validValues) && !in_array($attribute->value, $this->validValues ?? [])) { | ||
return false; | ||
} | ||
|
||
// No further tests required, attribute passes | ||
return true; | ||
} | ||
} |
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,98 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Forms\HTMLEditor; | ||
|
||
use DOMAttr; | ||
use DOMElement; | ||
|
||
class ElementRule // @TODO maybe we should have an ElementRules instead? And elementIsAllowed() checks against all rules for that element in the list? | ||
{ | ||
public string $name; | ||
// @TODO | ||
// Special "@" element (global rules) | ||
// e.g. "-b" - what's the prefix? | ||
// is ~ prefix handled? Used to be : prefix | ||
// What about any other special characters? | ||
/** | ||
* @todo | ||
* example | ||
* [ | ||
* 'id' => ?????? (they're stdClass rn for some reason?? Looks like it's related to "required/default/forced" | ||
* ] | ||
* @var AttributeRule[] | ||
*/ | ||
public array $attributes = []; | ||
|
||
/** | ||
* Undocumented variable | ||
* | ||
* @var AttributeRule[] | ||
*/ | ||
public array $attributePatterns; //@TODO what's that? | ||
public $attributesRequired = []; //@TODO what's that? | ||
public $attributesDefault = []; //@TODO what's that? | ||
public $attributesForced = []; //@TODO what's that? | ||
public bool $paddEmpty = false; //@TODO what's that? | ||
public bool $removeEmpty = false; //@TODO what's that? | ||
public string $outputName = ''; //@TODO what's that? | ||
// @TODO incl bool or enum or something for "is negation" i.e. some elements may be explicitly NOT allowed | ||
|
||
public function __construct(string $name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function elementIsAllowed(DOMElement $element): bool | ||
{ | ||
// @TODO consider whether to check the element type matches?? | ||
// If the rule has attributes required, check them to see if this element has at least one | ||
if ($this->attributesRequired) { | ||
$hasMatch = false; | ||
|
||
foreach ($this->attributesRequired as $attr) { | ||
if ($element->getAttribute($attr)) { | ||
$hasMatch = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!$hasMatch) { | ||
return false; | ||
} | ||
} | ||
|
||
// If the rule says to remove empty elements, and this element is empty, remove it | ||
if ($this->removeEmpty && !$element->firstChild) { | ||
return false; | ||
} | ||
|
||
// No further tests required, element passes | ||
return true; | ||
} | ||
|
||
public function attributeIsAllowed(DOMAttr $attribute): bool | ||
{ | ||
return $this->getRuleForAttribute($attribute->name)?->attributeIsAllowed($attribute); | ||
} | ||
|
||
private function getRuleForAttribute(string $name): AttributeRule | ||
{ | ||
if (isset($this->attributes[$name])) { | ||
return $this->attributes[$name]; | ||
} | ||
foreach ($this->attributePatterns as $attributeRule) { | ||
if (preg_match($attributeRule->name, $name)) { // @TODO maybe name isn't right for pattern? | ||
return $attributeRule; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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
Oops, something went wrong.