Skip to content
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

6.x: add docs for patchable changes #7979

Merged
merged 2 commits into from
Jan 7, 2025
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
22 changes: 20 additions & 2 deletions en/appendices/6-0-migration-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,26 @@ Behavior Changes
Breaking Changes
================

Datasource
----------

- ``Datasource/Paging/PaginatedInterface`` now extends ``IteratorAggregate``
instead of ``Traversable``.

ORM
---

- The ``_accessible`` property inside Entities has been renamed to ``patchable``
to better reflect its purpose.
- ``setAccess`` method has been renamed to ``setPatchable``.
- ``getAccessible`` method has been renamed to ``getPatchable``.
- ``isAccessible`` method has been renamed to ``isPatchable``.
- The ``accessibleFields`` option used in e.g. ORM Queries has been
renamed to ``patchableFields``.

Utility
-------

- The default placeholder format for ``Text::insert()`` has been changed.
They now use ``{foo}`` instead of ``:foo``. You can get the old
behavior by using the ``before`` and ``after`` keys of ``$options``.
- ``Datasource/Paging/PaginatedInterface`` now extends ``IteratorAggregate``
instead of ``Traversable``.
2 changes: 1 addition & 1 deletion en/orm/behaviors/translate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ In your controller, you can marshal the data as normal::

This will result in your article, the french and spanish translations all being
persisted. You'll need to remember to add ``_translations`` into the
``$_accessible`` fields of your entity as well.
``$patchable`` fields of your entity as well.

Validating Translated Entities
------------------------------
Expand Down
12 changes: 6 additions & 6 deletions en/orm/entities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ into an entity allows the user to modify any and all columns. When using
anonymous entity classes or creating the entity class with the :doc:`/bake`
CakePHP does not protect against mass-assignment.

The ``_accessible`` property allows you to provide a map of fields and
The ``patchable`` property allows you to provide a map of fields and
whether or not they can be mass-assigned. The values ``true`` and ``false``
indicate whether a field can or cannot be mass-assigned::

Expand All @@ -371,7 +371,7 @@ indicate whether a field can or cannot be mass-assigned::

class Article extends Entity
{
protected array $_accessible = [
protected array $patchable = [
'title' => true,
'body' => true
];
Expand All @@ -386,7 +386,7 @@ fallback behavior if a field is not specifically named::

class Article extends Entity
{
protected array $_accessible = [
protected array $patchable = [
'title' => true,
'body' => true,
'*' => false,
Expand All @@ -408,14 +408,14 @@ protect itself against mass assignment::
Modifying the Guarded Fields at Runtime
---------------------------------------

You can modify the list of guarded fields at runtime using the ``setAccess()``
You can modify the list of guarded fields at runtime using the ``setPatchable()``
method::

// Make user_id accessible.
$article->setAccess('user_id', true);
$article->setPatchable('user_id', true);

// Make title guarded.
$article->setAccess('title', false);
$article->setPatchable('title', false);

.. note::

Expand Down
12 changes: 6 additions & 6 deletions en/orm/saving-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ one or many entities from request data. You can convert a single entity using::

If you are using newEntity() and the resulting entities are missing some or
all of the data they were passed, double check that the columns you want to
set are listed in the ``$_accessible`` property of your entity. See :ref:`entities-mass-assignment`.
set are listed in the ``$patchable`` property of your entity. See :ref:`entities-mass-assignment`.

The request data should follow the structure of your entities. For example if
you have an article, which belonged to a user, and had many comments, your
Expand Down Expand Up @@ -365,8 +365,8 @@ Changing Accessible Fields
--------------------------

It's also possible to allow ``newEntity()`` to write into non accessible fields.
For example, ``id`` is usually absent from the ``_accessible`` property. In
such case, you can use the ``accessibleFields`` option. It could be useful to
For example, ``id`` is usually absent from the ``patchable`` property. In
such case, you can use the ``patchableFields`` option. It could be useful to
keep ids of associated entities::

// In a controller
Expand All @@ -377,7 +377,7 @@ keep ids of associated entities::
'Tags', 'Comments' => [
'associated' => [
'Users' => [
'accessibleFields' => ['id' => true],
'patchableFields' => ['id' => true],
],
],
],
Expand All @@ -391,7 +391,7 @@ concerned entity.

If you are using newEntity() and the resulting entities are missing some or
all of the data they were passed, double check that the columns you want to
set are listed in the ``$_accessible`` property of your entity. See
set are listed in the ``$patchable`` property of your entity. See
:ref:`entities-mass-assignment`.

Merging Request Data Into Entities
Expand Down Expand Up @@ -482,7 +482,7 @@ an important caveat:
If a Product belongsToMany Tag::

// in the Product Entity
protected array $_accessible = [
protected array $patchable = [
// .. other properties
'tags' => true,
];
Expand Down
4 changes: 2 additions & 2 deletions en/tutorials-and-examples/cms/articles-model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ look like this::

class Article extends Entity
{
protected array $_accessible = [
protected array $patchable = [
'user_id' => true,
'title' => true,
'slug' => true,
Expand All @@ -71,7 +71,7 @@ look like this::
];
}

Right now, our entity is quite slim; we've only set up the ``_accessible``
Right now, our entity is quite slim; we've only set up the ``patchable``
property, which controls how properties can be modified by
:ref:`entities-mass-assignment`.

Expand Down
2 changes: 1 addition & 1 deletion en/tutorials-and-examples/cms/authorization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Next we'll update the ``edit`` action. Replace the edit method with the followin
if ($this->request->is(['post', 'put'])) {
$this->Articles->patchEntity($article, $this->request->getData(), [
// Added: Disable modification of user_id.
'accessibleFields' => ['user_id' => false]
'patchableFields' => ['user_id' => false]
]);
if ($this->Articles->save($article)) {
$this->Flash->success(__('Your article has been updated.'));
Expand Down
2 changes: 1 addition & 1 deletion en/tutorials-and-examples/cms/tags-and-users.rst
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ can add a virtual/computed field to the entity. In
use Cake\Collection\Collection;

// Update the accessible property to contain `tag_string`
protected array $_accessible = [
protected array $patchable = [
//other fields...
'tag_string' => true
];
Expand Down
2 changes: 1 addition & 1 deletion en/views/helpers/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ to your form's view template file::
is displayed, the value inside will be empty.

To prevent the ``submittedfile`` from being over-written as blank, remove it
from ``$_accessible``. Alternatively, you can unset the index by using
from ``$patchable``. Alternatively, you can unset the index by using
``beforeMarshal``::

public function beforeMarshal(\Cake\Event\EventInterface $event, \ArrayObject $data, \ArrayObject $options)
Expand Down
2 changes: 1 addition & 1 deletion es/tutorials-and-examples/blog-auth-example/auth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ archivo de la entidad **src/Model/Entity/User.php** y añade lo siguiente::
class User extends Entity
{
// Make all fields mass assignable except for primary key field "id".
protected array $_accessible = [
protected array $patchable = [
'*' => true,
'id' => false
];
Expand Down
4 changes: 2 additions & 2 deletions es/tutorials-and-examples/cms/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ archivo completo debería verse así::

class Article extends Entity
{
protected array $_accessible = [
protected array $patchable = [
'title' => true,
'body' => true,
'published' => true,
Expand All @@ -219,7 +219,7 @@ archivo completo debería verse así::
}

Nuestra entidad es bastante delgada en este momento, y solo hemos configurado
la propiedad ``_accessible`` que controla cómo las propiedades pueden ser
la propiedad ``patchable`` que controla cómo las propiedades pueden ser
modificadas por `entities-mass-assignment`.

No podemos hacer mucho con nuestros modelos en este momento, así que a continuación
Expand Down
2 changes: 1 addition & 1 deletion fr/orm/behaviors/translate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ avec l'option ``translations`` activée::

Ceci va faire que votre article, les traductions françaises et espagnoles vont
tous persister. Vous devrez aussi vous souvenir d'ajouter ``_translations``
dans les champs accessibles ``$_accessible`` de votre entity.
dans les champs accessibles ``$patchable`` de votre entity.

Valider les Entities Traduites
------------------------------
Expand Down
12 changes: 6 additions & 6 deletions fr/orm/entities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ toutes). Utiliser des classes entity anonymes ou créer des classes entity avec
la commande :doc:`/bake` de CakePHP ne protège pas contre l'assignement en
masse.

La propriété ``_accessible`` vous permet de fournir une liste des champs et
La propriété ``patchable`` vous permet de fournir une liste des champs et
d'indiquer s'ils peuvent être assignés en masse ou non. Les valeurs ``true`` et
``false`` indiquent si un champ peut ou ne peut pas être assigné massivement::

Expand All @@ -398,7 +398,7 @@ d'indiquer s'ils peuvent être assignés en masse ou non. Les valeurs ``true`` e

class Article extends Entity
{
protected array $_accessible = [
protected array $patchable = [
'title' => true,
'body' => true
];
Expand All @@ -413,7 +413,7 @@ comportement par défaut si un champ n'est pas nommé spécifiquement::

class Article extends Entity
{
protected array $_accessible = [
protected array $patchable = [
'title' => true,
'body' => true,
'*' => false,
Expand All @@ -436,13 +436,13 @@ Modifier les Champs Protégés à la Volée
---------------------------------------

Vous pouvez modifier à la volée la liste des champs protégés en utilisant la
méthode ``setAccess()``::
méthode ``setPatchable()``::

// Rendre user_id accessible.
$article->setAccess('user_id', true);
$article->setPatchable('user_id', true);

// Rendre title protégé.
$article->setAccess('title', false);
$article->setPatchable('title', false);

.. note::

Expand Down
12 changes: 6 additions & 6 deletions fr/orm/saving-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ données de la requête. Vous pouvez convertir une entity unique en utilisant::

Si vous utilisez newEntity() et qu'il manque tout ou partie des nouvelles
données dans les entities créées, vérifiez que les colonnes que vous voulez
modifier sont listées dans la propriété ``$_accessible`` de votre entity.
modifier sont listées dans la propriété ``$patchable`` de votre entity.
Cf. :ref:`entities-mass-assignment`.

Les données de la requête doivent suivre la structure de vos entities. Par
Expand Down Expand Up @@ -388,8 +388,8 @@ Changer les Champs Accessibles

Il est également possible d'autoriser ``newEntity()`` à écrire dans des
champs non accessibles. Par exemple, ``id`` est généralement absent de la
propriété ``_accessible``. Dans un tel cas, vous pouvez utiliser l'option
``accessibleFields``. Il pourrait être utile de conserver les ids des entities
propriété ``patchable``. Dans un tel cas, vous pouvez utiliser l'option
``patchableFields``. Il pourrait être utile de conserver les ids des entities
associées::

// Dans un controller.
Expand All @@ -400,7 +400,7 @@ associées::
'Tags', 'Comments' => [
'associated' => [
'Users' => [
'accessibleFields' => ['id' => true],
'patchableFields' => ['id' => true],
],
],
],
Expand All @@ -414,7 +414,7 @@ l'entity concernée.

Si vous utilisez newEntity() et qu'il manque dans l'entity tout ou partie
des données transmises, vérifiez à deux fois que les colonnes
que vous souhaitez définir sont listées dans la propriété ``$_accessible``
que vous souhaitez définir sont listées dans la propriété ``$patchable``
de votre entity. Cf. :ref:`entities-mass-assignment`.

Fusionner les Données de la Requête dans les Entities
Expand Down Expand Up @@ -506,7 +506,7 @@ belongsToMany, avec cependant un point d'attention important:
Si Product belongsToMany Tag::

// Dans l'entity Product
protected array $_accessible = [
protected array $patchable = [
// .. autres propriétés
'tags' => true,
];
Expand Down
2 changes: 1 addition & 1 deletion fr/tutorials-and-examples/blog-auth-example/auth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ suit::
{

// Rend les champs assignables en masse sauf pour la clé primaire "id".
protected array $_accessible = [
protected array $patchable = [
'*' => true,
'id' => false
];
Expand Down
6 changes: 3 additions & 3 deletions fr/tutorials-and-examples/bookmarks/part-two.rst
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ pouvons ajouter un champ virtuel/calculé à l'entity. Dans

Cela nous laissera l'accès à la propriété calculée ``$bookmark->tag_string``.
Nous utiliserons cette propriété dans controls plus tard. Rappelez-vous
d'ajouter la propriété ``tag_string`` dans la liste ``_accessible`` de votre
d'ajouter la propriété ``tag_string`` dans la liste ``patchable`` de votre
entity, puisque nous voulons la 'sauvegarder' plus tard.

Dans le fichier **src/Model/Entity/Bookmark.php**, ajoutez ``tag_string`` à
la propriété ``_accessible`` comme ceci::
la propriété ``patchable`` comme ceci::

protected array $_accessible = [
protected array $patchable = [
'user_id' => true,
'title' => true,
'description' => true,
Expand Down
2 changes: 1 addition & 1 deletion fr/tutorials-and-examples/cms/authorization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Ensuite nous allons modifier l'action ``edit``. Remplacez la méthode d'édition
if ($this->request->is(['post', 'put'])) {
$this->Articles->patchEntity($article, $this->request->getData(), [
// Ajout: Empêcher la modification de user_id.
'accessibleFields' => ['user_id' => false]
'patchableFields' => ['user_id' => false]
]);
if ($this->Articles->save($article)) {
$this->Flash->success(__('Votre article a été sauvegardé.'));
Expand Down
4 changes: 2 additions & 2 deletions fr/tutorials-and-examples/cms/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ Le fichier devra ressembler à ceci::

class Article extends Entity
{
protected array $_accessible = [
protected array $patchable = [
'*' => true,
'id' => false,
'slug' => false,
];
}

Notre entity est assez simple pour l'instant et nous y avons seulement défini la
propriété ``_accessible`` qui permet de contrôler quelles propriétés peuvent être
propriété ``patchable`` qui permet de contrôler quelles propriétés peuvent être
modifiées via :ref:`entities-mass-assignment`.

Pour l'instant, nous ne pouvons pas faire grande chose avec notre model. Pour
Expand Down
2 changes: 1 addition & 1 deletion fr/tutorials-and-examples/cms/tags-and-users.rst
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ entity, nous ajoutons un champ virtuel/pré-calculé pour l'entity. Dans
use Cake\Collection\Collection;

// Mettez à jour la propriété accessible pour qu'elle contienne `tag_string`
protected array $_accessible = [
protected array $patchable = [
//autres champs...
'tag_string' => true
];
Expand Down
2 changes: 1 addition & 1 deletion fr/views/helpers/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ Ensuite ajoutez l'une des deux lignes dans votre formulaire::
À chaque affichage du formulaire, la valeur sera vide.

Pour empêcher le ``submittedfile`` d'être écrasé par un contenu vide, enlevez-le
de ``$_accessible``. Au choix, vous pouvez aussi retirer sa clé depuis la
de ``$patchable``. Au choix, vous pouvez aussi retirer sa clé depuis la
méthode ``beforeMarshal``::

public function beforeMarshal(\Cake\Event\EventInterface $event, \ArrayObject $data, \ArrayObject $options)
Expand Down
2 changes: 1 addition & 1 deletion ja/orm/behaviors/translate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ TranslateBehavior の背後にある哲学は、デフォルトの言語を表
$this->Articles->save($article);

これは、すべてが永続化されたフランス語とスペイン語の翻訳の記事になります。
同様に、エンティティーの ``$_accessible`` フィールドの中に
同様に、エンティティーの ``$patchable`` フィールドの中に
``_translations`` を追加することを忘れないでください。

翻訳されたエンティティーの検証
Expand Down
Loading
Loading