Skip to content

[5.x] Add failing test for issue caused by PR #9585 #10061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/Fields/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public function ensureFieldInTab($handle, $config, $tab, $prepend = false)

$this->ensuredFields[$handle] = compact('handle', 'tab', 'prepend', 'config');

$this->resetFieldsCache();
$this->resetBlueprintCache()->resetFieldsCache();

return $this;
}
Expand Down Expand Up @@ -573,7 +573,7 @@ public function removeTab($handle)

Arr::pull($this->contents['tabs'], $handle);

return $this->resetFieldsCache();
return $this->resetBlueprintCache()->resetFieldsCache();
}

public function removeFieldFromTab($handle, $tab)
Expand All @@ -591,7 +591,7 @@ public function removeFieldFromTab($handle, $tab)
// Pull it out.
Arr::pull($this->contents['tabs'][$tab]['sections'][$sectionIndex]['fields'], $fieldKey);

return $this->resetFieldsCache();
return $this->resetBlueprintCache()->resetFieldsCache();
}

private function getTabFields($tab)
Expand Down Expand Up @@ -621,7 +621,7 @@ protected function ensureFieldInTabHasConfig($handle, $tab, $config)
// Merge in new field config.
$this->contents['tabs'][$tab]['sections'][$sectionKey]['fields'][$fieldKey]['field'] = array_merge($existingConfig, $config);

return $this->resetFieldsCache();
return $this->resetBlueprintCache()->resetFieldsCache();
}

public function validateUniqueHandles()
Expand All @@ -635,6 +635,13 @@ public function validateUniqueHandles()
}
}

protected function resetBlueprintCache()
{
$this->lastBlueprintHandle = null;

return $this;
}

protected function resetFieldsCache()
{
if ($this->parent) {
Expand Down
24 changes: 24 additions & 0 deletions tests/Fields/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Statamic\Contracts\Query\QueryableValue;
use Statamic\CP\Column;
use Statamic\CP\Columns;
use Statamic\Entries\Entry;
use Statamic\Events\BlueprintCreated;
use Statamic\Events\BlueprintCreating;
use Statamic\Events\BlueprintDeleted;
Expand Down Expand Up @@ -783,6 +784,29 @@ public function it_ensures_a_field_exists_in_a_specific_tab()
$this->assertEquals(['type' => 'textarea'], $blueprint->fields()->get('new')->config());
}

/** @test */
public function it_can_add_fields_multiple_times()
{
$blueprint = (new Blueprint)
->setNamespace('collections/collection_one')
->setHandle('blueprint_one');

$entry = (new Entry)
->collection('collection_one')
->blueprint($blueprint);

$blueprint->setParent($entry);

$blueprint->ensureFieldsInTab(['field_one' => ['type' => 'text']], 'tab_one');

$this->assertTrue($blueprint->hasField('field_one'));

$blueprint->ensureField('field_two', ['type' => 'textarea']);

$this->assertTrue($blueprint->hasField('field_two'));

}

/** @test */
public function it_ensures_a_field_has_config()
{
Expand Down
Loading