Skip to content

Commit e931f1d

Browse files
authored
Merge pull request #7979 from cakephp/6.x-patchable
6.x: add docs for patchable changes
2 parents 9b340c5 + d16b738 commit e931f1d

File tree

31 files changed

+98
-80
lines changed

31 files changed

+98
-80
lines changed

en/appendices/6-0-migration-guide.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,26 @@ Behavior Changes
2020
Breaking Changes
2121
================
2222

23+
Datasource
24+
----------
25+
26+
- ``Datasource/Paging/PaginatedInterface`` now extends ``IteratorAggregate``
27+
instead of ``Traversable``.
28+
29+
ORM
30+
---
31+
32+
- The ``_accessible`` property inside Entities has been renamed to ``patchable``
33+
to better reflect its purpose.
34+
- ``setAccess`` method has been renamed to ``setPatchable``.
35+
- ``getAccessible`` method has been renamed to ``getPatchable``.
36+
- ``isAccessible`` method has been renamed to ``isPatchable``.
37+
- The ``accessibleFields`` option used in e.g. ORM Queries has been
38+
renamed to ``patchableFields``.
39+
40+
Utility
41+
-------
42+
2343
- The default placeholder format for ``Text::insert()`` has been changed.
2444
They now use ``{foo}`` instead of ``:foo``. You can get the old
2545
behavior by using the ``before`` and ``after`` keys of ``$options``.
26-
- ``Datasource/Paging/PaginatedInterface`` now extends ``IteratorAggregate``
27-
instead of ``Traversable``.

en/orm/behaviors/translate.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ In your controller, you can marshal the data as normal::
501501

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

506506
Validating Translated Entities
507507
------------------------------

en/orm/entities.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ into an entity allows the user to modify any and all columns. When using
361361
anonymous entity classes or creating the entity class with the :doc:`/bake`
362362
CakePHP does not protect against mass-assignment.
363363

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

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

372372
class Article extends Entity
373373
{
374-
protected array $_accessible = [
374+
protected array $patchable = [
375375
'title' => true,
376376
'body' => true
377377
];
@@ -386,7 +386,7 @@ fallback behavior if a field is not specifically named::
386386

387387
class Article extends Entity
388388
{
389-
protected array $_accessible = [
389+
protected array $patchable = [
390390
'title' => true,
391391
'body' => true,
392392
'*' => false,
@@ -408,14 +408,14 @@ protect itself against mass assignment::
408408
Modifying the Guarded Fields at Runtime
409409
---------------------------------------
410410

411-
You can modify the list of guarded fields at runtime using the ``setAccess()``
411+
You can modify the list of guarded fields at runtime using the ``setPatchable()``
412412
method::
413413

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

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

420420
.. note::
421421

en/orm/saving-data.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ one or many entities from request data. You can convert a single entity using::
139139

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

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

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

372372
// In a controller
@@ -377,7 +377,7 @@ keep ids of associated entities::
377377
'Tags', 'Comments' => [
378378
'associated' => [
379379
'Users' => [
380-
'accessibleFields' => ['id' => true],
380+
'patchableFields' => ['id' => true],
381381
],
382382
],
383383
],
@@ -391,7 +391,7 @@ concerned entity.
391391

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

397397
Merging Request Data Into Entities
@@ -482,7 +482,7 @@ an important caveat:
482482
If a Product belongsToMany Tag::
483483

484484
// in the Product Entity
485-
protected array $_accessible = [
485+
protected array $patchable = [
486486
// .. other properties
487487
'tags' => true,
488488
];

en/tutorials-and-examples/cms/articles-model.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ look like this::
5858

5959
class Article extends Entity
6060
{
61-
protected array $_accessible = [
61+
protected array $patchable = [
6262
'user_id' => true,
6363
'title' => true,
6464
'slug' => true,
@@ -71,7 +71,7 @@ look like this::
7171
];
7272
}
7373

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

en/tutorials-and-examples/cms/authorization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ Next we'll update the ``edit`` action. Replace the edit method with the followin
225225
if ($this->request->is(['post', 'put'])) {
226226
$this->Articles->patchEntity($article, $this->request->getData(), [
227227
// Added: Disable modification of user_id.
228-
'accessibleFields' => ['user_id' => false]
228+
'patchableFields' => ['user_id' => false]
229229
]);
230230
if ($this->Articles->save($article)) {
231231
$this->Flash->success(__('Your article has been updated.'));

en/tutorials-and-examples/cms/tags-and-users.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ can add a virtual/computed field to the entity. In
336336
use Cake\Collection\Collection;
337337

338338
// Update the accessible property to contain `tag_string`
339-
protected array $_accessible = [
339+
protected array $patchable = [
340340
//other fields...
341341
'tag_string' => true
342342
];

en/views/helpers/form.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ to your form's view template file::
15631563
is displayed, the value inside will be empty.
15641564

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

15691569
public function beforeMarshal(\Cake\Event\EventInterface $event, \ArrayObject $data, \ArrayObject $options)

es/tutorials-and-examples/blog-auth-example/auth.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ archivo de la entidad **src/Model/Entity/User.php** y añade lo siguiente::
157157
class User extends Entity
158158
{
159159
// Make all fields mass assignable except for primary key field "id".
160-
protected array $_accessible = [
160+
protected array $patchable = [
161161
'*' => true,
162162
'id' => false
163163
];

es/tutorials-and-examples/cms/database.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ archivo completo debería verse así::
208208

209209
class Article extends Entity
210210
{
211-
protected array $_accessible = [
211+
protected array $patchable = [
212212
'title' => true,
213213
'body' => true,
214214
'published' => true,
@@ -219,7 +219,7 @@ archivo completo debería verse así::
219219
}
220220

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

225225
No podemos hacer mucho con nuestros modelos en este momento, así que a continuación

0 commit comments

Comments
 (0)