diff --git a/src/Transformers/BardTransformer.php b/src/Transformers/BardTransformer.php index 57754bd..e32e21d 100644 --- a/src/Transformers/BardTransformer.php +++ b/src/Transformers/BardTransformer.php @@ -76,6 +76,35 @@ private function enableBardButtons(): void 'superscript', ]; + $importedField = $this->blueprint->fields()->items() + ->where('handle', $this->field->handle()) + ->filter(fn (array $field) => isset($field['field']) && is_string($field['field'])) + ->first(); + + if ($importedField) { + /** @var \Statamic\Fields\Fieldset $fieldset */ + $fieldHandle = Str::after($importedField['field'], '.'); + $fieldset = Fieldset::find(Str::before($importedField['field'], '.')); + + $fieldset->setContents([ + ...$fieldset->contents(), + 'fields' => collect($fieldset->contents()['fields']) + ->map(function (array $field) use ($buttons, $fieldHandle) { + if ($field['handle'] === $fieldHandle) { + return [ + 'handle' => $field['handle'], + 'field' => array_merge($field['field'], ['buttons' => $buttons]), + ]; + } + + return $field; + }) + ->all(), + ])->save(); + + return; + } + if ($prefix = $this->field->prefix()) { /** @var \Statamic\Fields\Fieldset $fieldset */ $fieldset = $this->blueprint->fields()->items() diff --git a/src/WordPress/Gutenberg.php b/src/WordPress/Gutenberg.php index 6e83de7..386eb96 100644 --- a/src/WordPress/Gutenberg.php +++ b/src/WordPress/Gutenberg.php @@ -406,6 +406,44 @@ protected static function ensureBardSet(Blueprint $blueprint, Field $field, stri return; } + $importedField = $blueprint->fields()->items() + ->where('handle', $field->handle()) + ->filter(fn (array $field) => isset($field['field']) && is_string($field['field'])) + ->first(); + + if ($importedField) { + /** @var \Statamic\Fields\Fieldset $fieldset */ + $fieldHandle = Str::after($importedField['field'], '.'); + $fieldset = Fieldset::find(Str::before($importedField['field'], '.')); + + $fieldset->setContents([ + ...$fieldset->contents(), + 'fields' => collect($fieldset->contents()['fields']) + ->map(function (array $fieldsetField) use ($field, $handle, $config, $fieldHandle) { + if ($fieldsetField['handle'] === $fieldHandle) { + return [ + 'handle' => $fieldsetField['handle'], + 'field' => array_merge($fieldsetField['field'], [ + ...$field->config(), + 'sets' => array_merge($field->get('sets', []), [ + 'main' => array_merge($field->get('sets.main', []), [ + 'sets' => array_merge($field->get('sets.main.sets', []), [ + $handle => $config, + ]), + ]), + ]), + ]), + ]; + } + + return $field; + }) + ->all(), + ])->save(); + + return; + } + if ($prefix = $field->prefix()) { /** @var \Statamic\Fields\Fieldset $fieldset */ $fieldset = $blueprint->fields()->items()