I am creating a custom entity (WebsiteType) with bundles (Website), where I want to define a URL, among other configurations, that all content in a given bundle should inherit.
I created the fields in the config entity type and managed to show and save these fields while creating a new bundle. Nevertheless, I couldn't manage to get these values in HOOK_entity_presave.
here is a sample of the code:
src/Entity/WebsiteType
Notation:
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid",
* "service_endpoint_url" = "service_endpoint_url",
Class:
class WebsiteType extends ConfigEntityBundleBase implements WebsiteTypeInterface {
/**
* The Website type Service Endpoint URL.
*
* @var string
*/
protected $service_endpoint_url;
}
/**
* {@inheritdoc}
*/
public function getServiceUrl() {
return $this->service_endpoint_url;
}
WebsiteTypeForm:
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$website_type = $this->entity;
$form['endpoint_settings']['service_endpoint_url'] = [
'#type' => 'textfield',
'#title' => $this->t('Argir Endpoint URL'),
'#maxlength' => 255,
'#description' => $this->t("The location of your service."),
'#required' => TRUE,
'#default_value' => $website_type->getServiceUrl(),
'#attributes' => [
'placeholder' => $this->t('https://XXXXX.com'),
],
];
}
WebsiteTypeInterface:
interface WebsiteTypeInterface extends ConfigEntityInterface {
public function getServiceUrl();
}
I followed the documentation of Drupal of Entity API
Checked the answer here: enter link description here
also went through this outstanding tutorial: enter link description here
Tried to work with EntityTypeManager
All of that with no luck. Any advice is highly appreciated.