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

Field config update code snippet for common settings #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tjheffner
Copy link

No description provided.


// Pop off the entity key & generic fields (nid, uuid, revision_log, etc).
$fields = array_slice($fields, 18, null, true);

Copy link
Member

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?

Copy link
Author

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) {
Copy link
Member

@mike-potter mike-potter Nov 4, 2016

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."

@tjheffner
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants