PHP code example of amcgowanca / discoverable_entity_bundle_classes
1. Go to this page and download the library: Download amcgowanca/discoverable_entity_bundle_classes library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amcgowanca / discoverable_entity_bundle_classes example snippets
/**
* Implements hook_entity_type_alter(&$entity_types)
*/
function my_module_entity_type_alter(&$entity_types) {
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
if (isset($entity_types['node'])) {
$entity_types['node']->setStorageClass('\Drupal\discoverable_entity_bundle_classes\Storage\Node\NodeStorage');
}
}
namespace Drupal\my_module\Entity;
use Drupal\node\Entity\Node;
class Article extends Node implements ArticleInterface {
...
}
namespace Drupal\my_module\Entity;
use Drupal\node\Entity\Node;
use Drupal\discoverable_entity_bundle_classes\ContentEntityBundleInterface;
class Article extends Node implements ArticleInterface, ContentEntityBundleInterface {
...
}
namespace Drupal\my_module\Entity;
use Drupal\node\Entity\Node;
use Drupal\discoverable_entity_bundle_classes\ContentEntityBundleInterface;
/**
* Defines an Article node class.
*
* @ContentEntityBundleClass(
* label = @Translation("Article"),
* entity_type = "node",
* bundle = "article"
* );
*/
class Article extends Node implements ArticleInterface, ContentEntityBundleInterface {
...
}