refactor: Detach – toter Zweig, benannte Argumente; VariableDetachRewrite-Docblock nennt leftover()
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
7608be6558
commit
5064409f9a
@@ -256,17 +256,17 @@ final class DiviDesignDetachAbility implements Ability, RequiresDiviFeatures
|
||||
}
|
||||
|
||||
return new DetachTarget(
|
||||
sprintf('Variable „%s“', $label),
|
||||
$postIds,
|
||||
new ReferenceUsageQuery([$id]),
|
||||
fn (): NodeRewrite => new VariableDetachRewrite($id, $value, $type, ($this->unfiltered)()),
|
||||
$nested
|
||||
subject: sprintf('Variable „%s“', $label),
|
||||
postIds: $postIds,
|
||||
query: new ReferenceUsageQuery([$id]),
|
||||
rewrite: fn (): NodeRewrite => new VariableDetachRewrite($id, $value, $type, ($this->unfiltered)()),
|
||||
presets: $nested
|
||||
? static fn (PresetBook $presets): PresetBook => $presets->withVariableResolved($id, $value, $affixes)
|
||||
: null,
|
||||
'Presets',
|
||||
$notes,
|
||||
self::ARCHIVE_HINT,
|
||||
$notes === []
|
||||
nestedIn: 'Presets',
|
||||
notes: $notes,
|
||||
doneHint: self::ARCHIVE_HINT,
|
||||
complete: $notes === []
|
||||
);
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ final class DiviDesignDetachAbility implements Ability, RequiresDiviFeatures
|
||||
{
|
||||
$problem = match (true) {
|
||||
$value === '' => 'ist leer',
|
||||
VariableDetachRewrite::unsafe($value, true) => 'enthält einen Verweis',
|
||||
VariableDetachRewrite::unsafe($value, markupAllowed: true) => 'enthält einen Verweis',
|
||||
VariableDetachRewrite::unsafe($value, ($this->unfiltered)()) => 'enthält Markup (< oder >), das dieses '
|
||||
. 'Konto nicht speichern darf (unfiltered_html)',
|
||||
default => null,
|
||||
@@ -336,15 +336,15 @@ final class DiviDesignDetachAbility implements Ability, RequiresDiviFeatures
|
||||
$nested = $postIds === null && $book->nestedUsers($id) !== [];
|
||||
|
||||
return new DetachTarget(
|
||||
sprintf('%s „%s“', $scope->label(), $label),
|
||||
$postIds,
|
||||
subject: sprintf('%s „%s“', $scope->label(), $label),
|
||||
postIds: $postIds,
|
||||
// Explicit references only (R10), also for a default preset: no withGroups(), implicit uses stay.
|
||||
new PresetUsageQuery([['scope' => $scope, 'id' => $id, 'default' => false]]),
|
||||
static fn (): NodeRewrite => new DetachRewrite($scope, $id),
|
||||
$nested ? static fn (PresetBook $presets): PresetBook => $presets->withoutNestedRef($id) : null,
|
||||
'anderen Presets',
|
||||
$book->defaultId($scope) === $id ? [sprintf(self::DEFAULT_NOTE, $label, $scope->name)] : [],
|
||||
self::DELETE_HINT
|
||||
query: new PresetUsageQuery([['scope' => $scope, 'id' => $id, 'default' => false]]),
|
||||
rewrite: static fn (): NodeRewrite => new DetachRewrite($scope, $id),
|
||||
presets: $nested ? static fn (PresetBook $presets): PresetBook => $presets->withoutNestedRef($id) : null,
|
||||
nestedIn: 'anderen Presets',
|
||||
notes: $book->defaultId($scope) === $id ? [sprintf(self::DEFAULT_NOTE, $label, $scope->name)] : [],
|
||||
doneHint: self::DELETE_HINT
|
||||
);
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ final class DiviDesignDetachAbility implements Ability, RequiresDiviFeatures
|
||||
{
|
||||
return function (array $raw) use ($target): DesignPlan|WP_Error {
|
||||
$before = PresetBook::fromDivi($raw);
|
||||
$after = $target->presets === null ? $before : ($target->presets)($before);
|
||||
$after = ($target->presets)($before);
|
||||
$diff = PresetDiff::between($before, $after);
|
||||
if ($diff === []) {
|
||||
return new DesignPlan($after->data(), [], PresetDiff::summary([]));
|
||||
|
||||
@@ -14,7 +14,7 @@ defined('ABSPATH') || exit;
|
||||
* with variable, ruling V9): every attribute value that is exactly one reference $variable({"type":"content",
|
||||
* "value":{"name":"<id>",…}})$ becomes the value – for a strings variable with the reference's own before/after
|
||||
* around it. References embedded in a longer text stay (Divi resolves them inside the text; cutting them out would
|
||||
* change the text) and are named in notes(). Other references – colors, other variables, dynamic content – stay
|
||||
* change the text) and are reported through leftover() (ReportsLeftovers). Other references – colors, other variables, dynamic content – stay
|
||||
* untouched. Pure PHP.
|
||||
*/
|
||||
final class VariableDetachRewrite implements NodeRewrite, ReportsLeftovers
|
||||
|
||||
Reference in New Issue
Block a user