Skip to content

Commit

Permalink
Merge branch '4.x' into feature/precognition
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Nov 14, 2023
2 parents 5406083 + 24b73ab commit f08b885
Show file tree
Hide file tree
Showing 30 changed files with 325 additions and 66 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Release Notes

## 4.34.0 (2023-11-14)

### What's new
- Auto-populate `array` fieldtype options. [#8980](https://github.com/statamic/cms/issues/8980) by @duncanmcclean
- Add Bard support to `read_time` modifier. [#8976](https://github.com/statamic/cms/issues/8976) by @duncanmcclean
- Antlers identifier finder. [#8965](https://github.com/statamic/cms/issues/8965) by @jasonvarga

### What's improved
- Nocache performance improvements. [#8956](https://github.com/statamic/cms/issues/8956) by @jasonvarga
- French translations. [#8977](https://github.com/statamic/cms/issues/8977) by @ebeauchamps

### What's fixed
- More php file validation. [#8991](https://github.com/statamic/cms/issues/8991) by @jasonvarga
- Fix super not saving on eloquent users. [#8979](https://github.com/statamic/cms/issues/8979) by @ryanmitchell
- Hide export submissions button when there are no valid exporters. [#8985](https://github.com/statamic/cms/issues/8985) by @ryanmitchell
- Only namespace asset validation attributes when on a CP route. [#8987](https://github.com/statamic/cms/issues/8987) by @ryanmitchell
- Fix for edit form page saying edit collection. [#8967](https://github.com/statamic/cms/issues/8967) by @ryanmitchell
- Fix new child entries not propagating to appropriate position in other sites trees. [#7302](https://github.com/statamic/cms/issues/7302) by @arthurperton
- Fix impersonation redirect. [#8973](https://github.com/statamic/cms/issues/8973) by @jasonvarga
- Fix error when getting alt on bard image when asset is missing. [#8959](https://github.com/statamic/cms/issues/8959) by @morphsteve
- Prevent requiring current password when changing another user's password. [#8966](https://github.com/statamic/cms/issues/8966) by @duncanmcclean
- Fix global attribute support on bard's small mark. [#8969](https://github.com/statamic/cms/issues/8969) by @jacksleight



## 4.33.0 (2023-11-10)

### What's new
Expand Down
3 changes: 2 additions & 1 deletion resources/js/components/collections/EditForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<header class="mb-6">
<breadcrumb :url="url" :title="values.title" />
<div class="flex items-center">
<h1 class="flex-1" v-text="__('Configure Collection')" />
<h1 class="flex-1" v-text="__(editTitle ?? 'Configure Collection')" />
<button type="submit" class="btn-primary" @click="submit">{{ __('Save') }}</button>
</div>
</header>
Expand All @@ -33,6 +33,7 @@ export default {
props: {
blueprint: Object,
editTitle: String,
initialValues: Object,
meta: Object,
url: String
Expand Down
18 changes: 16 additions & 2 deletions resources/js/components/fieldtypes/ArrayFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<tr class="sortable-row" v-for="(element, index) in data" :key="element._id">
<td class="sortable-handle table-drag-handle" v-if="!isReadOnly"></td>
<td>
<input type="text" class="input-text font-bold" v-model="element.key" :readonly="isReadOnly" />
<input type="text" class="input-text font-bold" v-model="element.key" :readonly="isReadOnly" @blur="keyUpdated(element)" />
</td>
<td>
<input type="text" class="input-text" v-model="element.value" :readonly="isReadOnly" />
Expand Down Expand Up @@ -210,7 +210,21 @@ export default {
setKey(key) {
this.selectedKey = key
}
},
keyUpdated(element) {
if (element.key === null || element.value !== null) {
return null;
}
let value = element.key.charAt(0).toUpperCase() + element.key.slice(1);
this.data.find((item, index) => {
if (item._id === element._id) {
this.data[index].value = value;
}
})
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions resources/lang/fr/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
'collections_route_instructions' => 'La route contrôle le modèle d’URL des entrées. Apprenez-en plus dans la [documentation](https://statamic.dev/collections#routing).',
'collections_sort_direction_instructions' => 'Le sens de tri par défaut.',
'collections_taxonomies_instructions' => 'Reliez les entrées de cette collection à des taxonomies. Les champs seront automatiquement ajoutés aux formulaires.',
'duplicate_action_warning_localization' => 'Cette entrée est une traduction. L’entrée originale est dupliquée.',
'duplicate_action_warning_localizations' => 'Une ou plusieurs entrées sélectionnées sont des traductions. Au lieu de cela, l’entrée originale est dupliquée.',
'duplicate_action_localizations_confirmation' => 'Êtes-vous sûr de vouloir effectuer cette action ? Les traductions sont également dupliquées.',
'duplicate_action_localizations_confirmation' => 'Êtes-vous sûr de vouloir effectuer cette action ? Les traductions seront également dupliquées.',
'duplicate_action_warning_localization' => 'Cette entrée est une traduction. L’entrée originale sera dupliquée.',
'duplicate_action_warning_localizations' => 'Une ou plusieurs entrées sélectionnées sont des traductions. Dans un tel cas, l’entrée originale sera dupliquée à la place.',
'email_utility_configuration_description' => 'Les paramètres de messagerie sont configurés dans <code>:path</code>',
'email_utility_description' => 'Vérifiez les paramètres de messagerie et envoyez des e-mails de test.',
'entry_origin_instructions' => 'La nouvelle traduction héritera des valeurs qu’a l’entrée dans le site sélectionné.',
Expand Down
1 change: 1 addition & 0 deletions resources/views/forms/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<collection-edit-form
initial-title="{{ $form->title() }}"
edit-title="Edit Form"
:blueprint="{{ json_encode($blueprint) }}"
:initial-values="{{ json_encode($values) }}"
:meta="{{ json_encode($meta) }}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/forms/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@endcan
</dropdown-list>

@if ($exporters = $form->exporters())
@if (($exporters = $form->exporters()) && $exporters->isNotEmpty())
<dropdown-list>
<button class="btn" slot="trigger">{{ __('Export Submissions') }}</button>
@foreach ($exporters as $exporter)
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/Impersonate.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ public function redirect($users, $values)
return $url;
}

return $users->first()->can('access cp') ? cp_route('dashboard') : '/';
return $users->first()->can('access cp') ? cp_route('index') : '/';
}
}
4 changes: 4 additions & 0 deletions src/Auth/Eloquent/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ public function __set($key, $value)
return $this->model()->timestamps = $value;
}

if ($key === 'super') {
return $this->model()->super = $value;
}

return $this->$key = $value;
}
}
31 changes: 31 additions & 0 deletions src/Entries/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Entries;

use ArrayAccess;
use Closure;
use Facades\Statamic\Entries\InitiatorStack;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Responsable;
Expand Down Expand Up @@ -722,13 +723,43 @@ public function makeLocalization($site)
->published($this->published)
->slug($this->slug());

if ($callback = $this->addToStructure($site, $this->parent())) {
$localization->afterSave($callback);
}

if ($this->collection()->dated()) {
$localization->date($this->date());
}

return $localization;
}

private function addToStructure($site, $parent = null): ?Closure
{
// If it's orderable (linear - a max depth of 1) then don't add it.
if ($this->collection()->orderable()) {
return null;
}

// Collection not structured? Don't add it.
if (! $structure = $this->collection()->structure()) {
return null;
}

$tree = $structure->in($site);
$parent = optional($parent)->in($site);

return function ($entry) use ($parent, $tree) {
if (! $parent || $parent->isRoot()) {
$tree->append($entry);
} else {
$tree->appendTo($parent->id(), $entry);
}

$tree->save();
};
}

public function supplementTaxonomies()
{
// TODO: This is just here to make things work without rewriting a bunch of places.
Expand Down
3 changes: 2 additions & 1 deletion src/Fieldtypes/Assets/DimensionsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Validation\Rule;
use Statamic\Facades\Asset;
use Statamic\Statamic;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class DimensionsRule implements Rule
Expand Down Expand Up @@ -63,7 +64,7 @@ public function passes($attribute, $value)
*/
public function message()
{
return __('statamic::validation.dimensions');
return __((Statamic::isCpRoute() ? 'statamic::' : '').'validation.dimensions');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Fieldtypes/Assets/ImageRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Validation\Rule;
use Statamic\Facades\Asset;
use Statamic\Statamic;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class ImageRule implements Rule
Expand Down Expand Up @@ -46,6 +47,6 @@ public function passes($attribute, $value)
*/
public function message()
{
return __('statamic::validation.image');
return __((Statamic::isCpRoute() ? 'statamic::' : '').'validation.image');
}
}
4 changes: 3 additions & 1 deletion src/Fieldtypes/Assets/MaxRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Statamic\Fieldtypes\Assets;

use Statamic\Statamic;

class MaxRule extends SizeBasedRule
{
/**
Expand All @@ -22,6 +24,6 @@ public function sizePasses($size)
*/
public function message()
{
return str_replace(':max', $this->parameters[0], __('statamic::validation.max.file'));
return str_replace(':max', $this->parameters[0], __((Statamic::isCpRoute() ? 'statamic::' : '').'validation.max.file'));
}
}
3 changes: 2 additions & 1 deletion src/Fieldtypes/Assets/MimesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Validation\Rule;
use Statamic\Facades\Asset;
use Statamic\Statamic;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class MimesRule implements Rule
Expand Down Expand Up @@ -48,6 +49,6 @@ public function passes($attribute, $value)
*/
public function message()
{
return str_replace(':values', implode(', ', $this->parameters), __('statamic::validation.mimes'));
return str_replace(':values', implode(', ', $this->parameters), __((Statamic::isCpRoute() ? 'statamic::' : '').'validation.mimes'));
}
}
3 changes: 2 additions & 1 deletion src/Fieldtypes/Assets/MimetypesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Validation\Rule;
use Statamic\Facades\Asset;
use Statamic\Statamic;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class MimetypesRule implements Rule
Expand Down Expand Up @@ -43,6 +44,6 @@ public function passes($attribute, $value)
*/
public function message()
{
return str_replace(':values', implode(', ', $this->parameters), __('statamic::validation.mimetypes'));
return str_replace(':values', implode(', ', $this->parameters), __((Statamic::isCpRoute() ? 'statamic::' : '').'validation.mimetypes'));
}
}
4 changes: 3 additions & 1 deletion src/Fieldtypes/Assets/MinRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Statamic\Fieldtypes\Assets;

use Statamic\Statamic;

class MinRule extends SizeBasedRule
{
/**
Expand All @@ -22,6 +24,6 @@ public function sizePasses($size)
*/
public function message()
{
return str_replace(':min', $this->parameters[0], __('statamic::validation.min.file'));
return str_replace(':min', $this->parameters[0], __((Statamic::isCpRoute() ? 'statamic::' : '').'validation.min.file'));
}
}
4 changes: 2 additions & 2 deletions src/Fieldtypes/Bard/ImageNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public function renderHTML($node, $HTMLAttributes = [])

protected function getUrl($id)
{
return optional(Asset::find($id))->url();
return Asset::find($id)?->url();
}

protected function getAlt($id)
{
return optional(Asset::find($id))->data()->get('alt');
return Asset::find($id)?->data()->get('alt');
}
}
2 changes: 1 addition & 1 deletion src/Http/Controllers/CP/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function store(Request $request)
'container' => 'required',
'folder' => 'required',
'file' => ['file', function ($attribute, $value, $fail) {
if (in_array(trim(strtolower($value->getClientOriginalExtension())), ['php', 'php3', 'php4', 'php5', 'phtml'])) {
if (in_array(trim(strtolower($value->getClientOriginalExtension())), ['php', 'php3', 'php4', 'php5', 'php7', 'php8', 'phtml', 'phar'])) {
$fail(__('validation.uploaded'));
}
}],
Expand Down
28 changes: 0 additions & 28 deletions src/Http/Controllers/CP/Collections/LocalizeEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,11 @@ public function __invoke(Request $request, $collection, $entry)

$localized = $entry->makeLocalization($site = $request->site);

$this->addToStructure($collection, $entry, $localized);

$localized->store(['user' => User::fromUser($request->user())]);

return [
'handle' => $site,
'url' => $localized->editUrl(),
];
}

private function addToStructure($collection, $entry, $localized)
{
// If it's orderable (linear - a max depth of 1) then don't add it.
if ($collection->orderable()) {
return;
}

// Collection not structured? Don't add it.
if (! $structure = $collection->structure()) {
return;
}

$tree = $structure->in($localized->locale());
$parent = optional($entry->parent())->in($localized->locale());

$localized->afterSave(function ($localized) use ($parent, $tree) {
if (! $parent || $parent->isRoot()) {
$tree->append($localized);
} else {
$tree->appendTo($parent->id(), $localized);
}

$tree->save();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function upload(Request $request)
{
$request->validate([
'file' => ['file', function ($attribute, $value, $fail) {
if (in_array(trim(strtolower($value->getClientOriginalExtension())), ['php', 'php3', 'php4', 'php5', 'phtml'])) {
if (in_array(trim(strtolower($value->getClientOriginalExtension())), ['php', 'php3', 'php4', 'php5', 'php7', 'php8', 'phtml', 'phar'])) {
$fail(__('validation.uploaded'));
}
}],
Expand Down
8 changes: 8 additions & 0 deletions src/Modifiers/CoreModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,14 @@ public function ray($value)
*/
public function readTime($value, $params)
{
if (is_array($value)) {
$value = collect($value)
->map(fn (Values $values) => $values->all())
->where('type', 'text')
->map(fn ($item) => $item['text']->raw())
->implode(' ');
}

$words = $this->wordCount(strip_tags($value));

return ceil($words / Arr::get($params, 0, 200));
Expand Down
Loading

0 comments on commit f08b885

Please sign in to comment.