Skip to content
Snippets Groups Projects
Select Git revision
  • 059807a65a77d88ffe77496b27156b2865a12d9b
  • 4.x default
  • 3.x
  • 2.x
  • 8.x-1.x
  • 7.x-1.x
  • 4.1.0
  • 4.0.12
  • 4.0.11
  • 4.0.10
  • 4.0.9
  • 4.0.8
  • 4.0.7
  • 4.0.6
  • previous/3228271-broken-link-check/2021-08-20
  • 4.0.5
  • 4.0.4
  • 4.0.3
  • 4.0.2
  • 4.0.1
  • 4.0.0-alpha3
  • 4.0.0-alpha2
  • 4.0.0-alpha1
  • 3.0.2
  • 3.0.1
  • 3.0.0
26 results

typed_entity_example.module

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    typed_entity_example.module 1.54 KiB
    <?php
    
    /**
     * @file
     * Module implementation file.
     */
    
    use Drupal\typed_entity\TypedEntity\TypedEntityManager;
    
    /**
     * Implements hook_typed_entity_registry_info().
     */
    function typed_entity_example_typed_entity_registry_info() {
      $items['article'] = array(
        'entity_type' => 'node',
        'bundle' => 'article',
        'class' => '\\Drupal\\typed_entity_example\\TypedEntity\\Node\\Article',
      );
    
      return $items;
    }
    
    /**
     * Implements hook_menu().
     */
    function typed_entity_example_menu() {
      $items['node/%node/typed'] = array(
        'title' => 'Typed node',
        'description' => 'Shows the typed node.',
        'page callback' => 'typed_entity_example_node_typed',
        'page arguments' => array(1),
        'type' => MENU_LOCAL_TASK,
        'access arguments' => array('administer nodes'),
      );
      return $items;
    }
    
    /**
     * Page callback that displays the typed entity.
     *
     * @param object $node
     *   The loaded node.
     *
     * @return string
     *   The page content.
     */
    function typed_entity_example_node_typed($node) {
      /** @var \Drupal\typed_entity_example\TypedEntity\Node\Article $typed_node */
      $typed_node = TypedEntityManager::create('node', $node);
      drupal_set_title($typed_node->title);
    
      if ($typed_image = $typed_node->getImage()) {
        $output = array();
        $uri = $typed_image->uri;
        if (!empty($uri)) {
          $output['image'] = array(
            '#theme' => 'image',
            '#path' => $typed_image->uri,
          );
        }
      }
      $output['debug'] = array(
        '#type' => 'html_tag',
        '#tag' => 'pre',
        '#value' => print_r($typed_node, TRUE),
      );
    
      return $output;
    }