Categories
CMS Drupal Mastering Development

How to create a term reference field programmatically

I need to add a taxonomy reference field to a node bundle, programmatically. I found a couple examples here, but one actually is incorrectly titled and is about creating a from field for it, and the other is from 2012. I have tried the following, based on the couple of suggested examples I found, and […]

Categories
CMS Development Drupal

Why is my site status continuing to indicate mismatched field definitions after updating?

When I visit /admin/reports/status, I am told that a few entities have fields that need to be updated or reinstalled. I created an update hook: /** * Remove the result field from the analysis entity and reinstall */ function mymodule_update_8101(&$sandbox) { $entity_name = ‘analysis’; $old_field_name = ‘result’; $new_field_name = ‘result’; $field_definition = BaseFieldDefinition::create(‘decimal’) ->setLabel(t(‘Results’)) ->setDescription(t(‘Results.’)) […]

Categories
CMS Development Drupal

Set display options for a json string in drupal 8 BaseFieldDefinition:

I have a field that stores a json string with keys and values in the database. I wish to format this output from my field definition display option to output the json string as a list. Is it possible to achieve this via such an approach? $fields[‘charges’] = BaseFieldDefinition::create(‘string’) ->setLabel(t(‘Charges’)) ->setDescription(t(‘The events charges in Ksh.’)) […]

Categories
CMS Development Drupal

How to change field attributes of Content Entity?

In a custom module, I have a content entity in which I have defined this field: $fields[‘formheader’] = BaseFieldDefinition::create(‘string’) ->setLabel(t(‘Header’)) ->setSettings([ ‘max_length’ => 255, ‘text_processing’ => 0, ]) ->setDefaultValue(”) ->setDisplayOptions(‘view’, [ ‘label’ => ‘above’, ‘type’ => ‘string’, ‘weight’ => $weight, ]) ->setDisplayOptions(‘form’, [ ‘type’ => ‘string_textfield’, ‘weight’ => $weight, ]) ->setDisplayConfigurable(‘form’, TRUE) ->setDisplayConfigurable(‘view’, TRUE); I’d […]