0
    function some_config_update_8101(){


if ( !FieldConfig::load('image_byline') ){
    $config_path = drupal_get_path('module', 'some_config') . '/config/install/field.field.node.main_image.field_image_byline.yml';
    $data = Yaml::parse($config_path);
    \Drupal::configFactory()->getEditable('field.field.node.main_image.field_image_byline')->setData($data)->save(TRUE);
    $message .= "FieldConfig installed for module some_config.\n";
  }
  else {
    $message .= "It didn't work!\n";
  }


     if( !FieldConfigStorage::load('image_byline') ){
        $config_path = drupal_get_path('module', 'some_config') . '/config/install/field.storage.node.field_image_byline.yml';
        $data = Yaml::parse($config_path);
        \Drupal::configFactory()->getEditable('field.storage.node.field_image_byline')->setData($data)->save(TRUE);
        $message .= "FieldConfigStorage installed for module some_config.\n";
     }
     else{
       $message .= "That didn't work either!\n";
    }

Above is the code I am attempting to use to update a content type with a new field on my site. When I run the dbup command I get "PHP Fatal error: Using $this when not in object context in EntityStoageBase.php.

How is my code affecting the context of EntityStorageBase, if I have not changed code in that file?

0

FieldConfigStorage::load() isn't static, so you can't use it statically.

Get an instance of FieldConfigStorage instead, and use that

if ($storage->load('image_byline')) {
  // ...
}
  • I have used Node::load() why is this any different? dont they both override EntityStorageInterface::load ? – BrandenB171 Mar 17 '16 at 16:17
  • 1
    No, one's for the config (extends FieldConfigBase) and the other is for storage (FieldConfigStorageBase). Totally different classes, though they complement one another – Clive Mar 17 '16 at 16:21
  • 1
    The example just uses the wrong class name, should be FieldStorageConfig, wihch is a config entity too. Also, the ID of them is entity_type.bundle.fieldname for the field config, and entity_type.fieldname for the field storage config. – Berdir Mar 17 '16 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.