-
Notifications
You must be signed in to change notification settings - Fork 7
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
Field config update code snippet for common settings #1
base: master
Are you sure you want to change the base?
Conversation
|
||
// Pop off the entity key & generic fields (nid, uuid, revision_log, etc). | ||
$fields = array_slice($fields, 18, null, true); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "18" a magic number? How would you do this more generically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
18 is a magic number, because when I var_dump($fields), the first 18 results for node fields are:
[0]=>
string(3) "nid"
[1]=>
string(4) "uuid"
[2]=>
string(3) "vid"
[3]=>
string(8) "langcode"
[4]=>
string(4) "type"
[5]=>
string(5) "title"
[6]=>
string(3) "uid"
[7]=>
string(6) "status"
[8]=>
string(7) "created"
[9]=>
string(7) "changed"
[10]=>
string(7) "promote"
[11]=>
string(6) "sticky"
[12]=>
string(18) "revision_timestamp"
[13]=>
string(12) "revision_uid"
[14]=>
string(12) "revision_log"
[15]=>
string(29) "revision_translation_affected"
[16]=>
string(16) "default_langcode"
[17]=>
string(4) "path"
I think there is a isBaseField() method somewhere that would probably be better to check against, but I was having trouble calling it in this case.
$field_name = $keys[$key]; | ||
$bundles = $fields[$value]['bundles']; | ||
|
||
foreach ($bundles as $bundle) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need a comment here to say something like "In this example, we will set each field instance to be optional. Replace this with whatever specific code you need to change the field instances."
Updated to use the generic $entityFieldManager->getBaseFieldDefinitions('node'); instead of an arbitrary array_slice. Added a comment to the bundle loop that changes the setting itself. |
No description provided.