예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function view(EntityInterface $entity)
 {
     if ($entity instanceof FileInterface) {
         return ['#theme' => 'image_style', '#style_name' => $this->configuration['image_style'], '#title' => $entity->label(), '#alt' => $entity->label(), '#uri' => $entity->getFileUri()];
     }
     return $entity->label();
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\embed\EmbedButtonInterface $entity */
     $row = [];
     $row['label'] = $entity->label();
     $row['embed_type'] = $entity->getTypeLabel();
     if ($icon_url = $entity->getIconUrl()) {
         $row['icon']['data'] = ['#theme' => 'image', '#uri' => $icon_url, '#alt' => $this->t('Icon for the @label button.', ['@label' => $entity->label()])];
     } else {
         $row['icon'] = $this->t('None');
     }
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var $entity SearchApiPage */
     $row['label'] = $entity->label();
     $row['path'] = \Drupal::l($entity->getPath(), Url::fromRoute('search_api_page.' . $entity->id()));
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\drupal8_entity\Entity\Drupal8EntityItem */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($entity->label(), new Url('entity.drupal8_entity_item.edit_form', array('drupal8_entity_item' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
 /**
  * Tests the label formatter.
  */
 public function testLabelFormatter()
 {
     $formatter = 'entity_reference_label';
     // The 'link' settings is TRUE by default.
     $build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
     $expected_item_1 = array('#type' => 'link', '#title' => $this->referencedEntity->label(), '#url' => $this->referencedEntity->urlInfo(), '#options' => $this->referencedEntity->urlInfo()->getOptions(), '#cache' => array('tags' => $this->referencedEntity->getCacheTags()));
     $this->assertEqual(drupal_render($build[0]), drupal_render($expected_item_1), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
     // The second referenced entity is "autocreated", therefore not saved and
     // lacking any URL info.
     $expected_item_2 = array('#markup' => $this->unsavedReferencedEntity->label(), '#cache' => array('tags' => $this->unsavedReferencedEntity->getCacheTags()));
     $this->assertEqual($build[1], $expected_item_2, sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
     // Test with the 'link' setting set to FALSE.
     $build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter, array('link' => FALSE));
     $this->assertEqual($build[0]['#markup'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
     $this->assertEqual($build[1]['#markup'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
     // Test an entity type that doesn't have any link templates, which means
     // \Drupal\Core\Entity\EntityInterface::urlInfo() will throw an exception
     // and the label formatter will output only the label instead of a link.
     $field_storage_config = FieldStorageConfig::loadByName($this->entityType, $this->fieldName);
     $field_storage_config->setSetting('target_type', 'entity_test_label');
     $field_storage_config->save();
     $referenced_entity_with_no_link_template = entity_create('entity_test_label', array('name' => $this->randomMachineName()));
     $referenced_entity_with_no_link_template->save();
     $build = $this->buildRenderArray([$referenced_entity_with_no_link_template], $formatter, array('link' => TRUE));
     $this->assertEqual($build[0]['#markup'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter));
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\drupalbristol_sponsors\Entity\SponsorEntity */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($entity->label(), new Url('entity.sponsor.edit_form', array('sponsor' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row = [];
     $row['name'] = $entity->label();
     $row['type'] = $entity->id();
     return $row + parent::buildRow($entity);
 }
예제 #8
0
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    /** @var \Drupal\entity_clone\EntityClone\EntityCloneInterface $entity_clone_handler */
    $entity_clone_handler = $this->entityTypeManager->getHandler($this->entityTypeDefinition->id(), 'entity_clone');
    if ($this->entityTypeManager->hasHandler($this->entityTypeDefinition->id(), 'entity_clone_form')) {
      $entity_clone_form_handler = $this->entityTypeManager->getHandler($this->entityTypeDefinition->id(), 'entity_clone_form');
    }

    $properties = [];
    if (isset($entity_clone_form_handler) && $entity_clone_form_handler) {
      $properties = $entity_clone_form_handler->getNewValues($form_state);
    }

    $cloned_entity = $entity_clone_handler->cloneEntity($this->entity, $this->entity->createDuplicate(), $properties);

    drupal_set_message($this->stringTranslationManager->translate('The entity <em>@entity (@entity_id)</em> of type <em>@type</em> was cloned', [
      '@entity' => $this->entity->label(),
      '@entity_id' => $this->entity->id(),
      '@type' => $this->entity->getEntityTypeId(),
    ]));

    if ($cloned_entity && $cloned_entity->hasLinkTemplate('canonical')) {
      $form_state->setRedirect($cloned_entity->toUrl()
        ->getRouteName(), $cloned_entity->toUrl()->getRouteParameters());
    }

    $form_state->setRedirect('<front>');
  }
    /**
     * Tests the entity formatter.
     */
    public function testEntityFormatter()
    {
        $formatter = 'entity_reference_entity_view';
        $field_name = $this->fieldName;
        // Create the entity that will have the entity reference field.
        $referencing_entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
        $referencing_entity->save();
        $referencing_entity->{$field_name}->entity = $this->referencedEntity;
        $referencing_entity->{$field_name}->access = TRUE;
        // Build the renderable array for the entity reference field.
        $items = $referencing_entity->get($field_name);
        $build = $items->view(array('type' => $formatter));
        $expected_rendered_name_field = '<div class="field field-entity-test--name field-name-name field-type-string field-label-hidden">
    <div class="field-items">
          <div class="field-item">' . $this->referencedEntity->label() . '</div>
      </div>
</div>
';
        $expected_rendered_body_field = '<div class="field field-entity-test--body field-name-body field-type-text field-label-above">
      <div class="field-label">Body:&nbsp;</div>
    <div class="field-items">
          <div class="field-item"><p>Hello, world!</p></div>
      </div>
</div>
';
        drupal_render($build[0]);
        $this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field . $expected_rendered_body_field, format_string('The markup returned by the @formatter formatter is correct.', array('@formatter' => $formatter)));
        $expected_cache_tags = Cache::mergeTags(\Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTag(), $this->referencedEntity->getCacheTag(), FilterFormat::load('full_html')->getCacheTag());
        $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter)));
    }
 /**
  * Renders the Metatag defaults label plus its configuration.
  *
  * @param EntityInterface $entity
  *   The Metatag defaults entity.
  *
  * @return
  *   Render array for a table cell.
  */
 public function getLabelAndConfig(EntityInterface $entity)
 {
     $output = '<div>';
     $prefix = '';
     $inherits = '';
     if ($entity->id() != 'global') {
         $prefix = '<div class="indentation"></div>';
         $inherits .= 'Global';
     }
     if (strpos($entity->id(), '__') !== FALSE) {
         $prefix .= '<div class="indentation"></div>';
         list($entity_label, $bundle_label) = explode(': ', $entity->get('label'));
         $inherits .= ', ' . $entity_label;
     }
     if (!empty($inherits)) {
         $output .= '<div><p>' . t('Inherits meta tags from: @inherits', ['@inherits' => $inherits]) . '</p></div>';
     }
     $tags = $entity->get('tags');
     if (count($tags)) {
         $output .= '<table>
                 <tbody>';
         foreach ($tags as $tag_id => $tag_value) {
             $output .= '<tr><td>' . $tag_id . ':</td><td>' . $tag_value . '</td></tr>';
         }
         $output .= '</tbody></table>';
     }
     $output .= '</div></div>';
     return ['data' => ['#type' => 'details', '#prefix' => $prefix, '#title' => $entity->label(), 'config' => ['#markup' => $output]]];
 }
 /**
  * Tests the label formatter.
  */
 public function testLabelFormatter()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     $formatter = 'entity_reference_label';
     // The 'link' settings is TRUE by default.
     $build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
     $expected_field_cacheability = ['contexts' => [], 'tags' => [], 'max-age' => Cache::PERMANENT];
     $this->assertEqual($build['#cache'], $expected_field_cacheability, 'The field render array contains the entity access cacheability metadata');
     $expected_item_1 = array('#type' => 'link', '#title' => $this->referencedEntity->label(), '#url' => $this->referencedEntity->urlInfo(), '#options' => $this->referencedEntity->urlInfo()->getOptions(), '#cache' => array('contexts' => ['user.permissions'], 'tags' => $this->referencedEntity->getCacheTags()));
     $this->assertEqual($renderer->renderRoot($build[0]), $renderer->renderRoot($expected_item_1), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
     $this->assertEqual(CacheableMetadata::createFromRenderArray($build[0]), CacheableMetadata::createFromRenderArray($expected_item_1));
     // The second referenced entity is "autocreated", therefore not saved and
     // lacking any URL info.
     $expected_item_2 = array('#plain_text' => $this->unsavedReferencedEntity->label(), '#cache' => array('contexts' => ['user.permissions'], 'tags' => $this->unsavedReferencedEntity->getCacheTags(), 'max-age' => Cache::PERMANENT));
     $this->assertEqual($build[1], $expected_item_2, sprintf('The render array returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
     // Test with the 'link' setting set to FALSE.
     $build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter, array('link' => FALSE));
     $this->assertEqual($build[0]['#plain_text'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
     $this->assertEqual($build[1]['#plain_text'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
     // Test an entity type that doesn't have any link templates, which means
     // \Drupal\Core\Entity\EntityInterface::urlInfo() will throw an exception
     // and the label formatter will output only the label instead of a link.
     $field_storage_config = FieldStorageConfig::loadByName($this->entityType, $this->fieldName);
     $field_storage_config->setSetting('target_type', 'entity_test_label');
     $field_storage_config->save();
     $referenced_entity_with_no_link_template = EntityTestLabel::create(array('name' => $this->randomMachineName()));
     $referenced_entity_with_no_link_template->save();
     $build = $this->buildRenderArray([$referenced_entity_with_no_link_template], $formatter, array('link' => TRUE));
     $this->assertEqual($build[0]['#plain_text'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter));
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\scheduled_updates\Entity\ScheduledUpdate */
     $row['name'] = $this->l($entity->label(), new Url('entity.scheduled_update.edit_form', array('scheduled_update' => $entity->id())));
     $row['type'] = $this->updateUtils->getUpdateTypeLabel($entity);
     return $row + parent::buildRow($entity);
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\commerce_tax\Entity\TaxTypeInterface $entity */
     $row['name'] = $entity->label();
     $row['tag'] = $entity->getTag();
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $entity->label();
     $row['id'] = $entity->id();
     // Render encryption method row.
     if ($encryption_method = $entity->getEncryptionMethod()) {
         $row['encryption_method'] = $encryption_method->getLabel();
     } else {
         $row['encryption_method'] = $this->t('Error loading encryption method');
     }
     // Render encryption key row.
     if ($key = $entity->getEncryptionKey()) {
         $row['key'] = $key->label();
     } else {
         $row['key'] = $this->t('Error loading key');
     }
     // Render status report row.
     if ($this->config->get('check_profile_status')) {
         $errors = $entity->validate();
         if (!empty($errors)) {
             $row['status']['data'] = array('#theme' => 'item_list', '#items' => $errors, '#attributes' => array("class" => array("color-error")));
         } else {
             $row['status'] = $this->t('OK');
         }
     }
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $entity->label();
     $row['id'] = $entity->id();
     // You probably want a few more properties here...
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     // Save as a new revision if requested to do so.
     if (!$form_state->isValueEmpty('revision')) {
         $this->entity->setNewRevision();
     }
     $insert = $this->entity->isNew();
     $this->entity->save();
     $context = ['@type' => $this->entity->bundle(), '%info' => $this->entity->label()];
     $logger = $this->logger($this->entity->id());
     $bundle_entity = $this->getBundleEntity();
     $t_args = ['@type' => $bundle_entity ? $bundle_entity->label() : 'None', '%info' => $this->entity->label()];
     if ($insert) {
         $logger->notice('@type: added %info.', $context);
         drupal_set_message($this->t('@type %info has been created.', $t_args));
     } else {
         $logger->notice('@type: updated %info.', $context);
         drupal_set_message($this->t('@type %info has been updated.', $t_args));
     }
     if ($this->entity->id()) {
         $form_state->setValue('id', $this->entity->id());
         $form_state->set('id', $this->entity->id());
         if ($this->entity->getEntityType()->hasLinkTemplate('collection')) {
             $form_state->setRedirectUrl($this->entity->toUrl('collection'));
         } else {
             $form_state->setRedirectUrl($this->entity->toUrl('canonical'));
         }
     } else {
         // In the unlikely case something went wrong on save, the entity will be
         // rebuilt and entity form redisplayed.
         drupal_set_message($this->t('The entity could not be saved.'), 'error');
         $form_state->setRebuild();
     }
 }
예제 #17
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $entity->label();
     $row['provider'] = $this->keyProviderPluginManager->getDefinition($entity->getKeyProvider())['title'];
     $row['service_default'] = $entity->getServiceDefault() ? "Yes" : "No";
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\content_entity_example\Entity\OnlineMessage */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($entity->label(), new Url('entity.online_message.edit_form', array('online_message' => $entity->id())));
     return $row + parent::buildRow($entity);
 }
예제 #19
0
 /**
  * Prepares the link to the profile.
  *
  * @param \Drupal\Core\Entity\EntityInterface $profile
  *   The profile entity this field belongs to.
  * @param ResultRow $values
  *   The values retrieved from the view's result set.
  *
  * @return string
  *   Returns a string for the link text.
  */
 protected function renderLink($profile, ResultRow $values) {
   if ($profile->access('view')) {
     $this->options['alter']['make_link'] = TRUE;
     $this->options['alter']['path'] = 'profile/' . $profile->id();
     return $profile->label();
   }
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['to']['#markup'] = $this->stateStorage->load($entity->getToState())->label();
     $row['label'] = $entity->label();
     $row['roles']['#markup'] = implode(', ', user_role_names(FALSE, 'use ' . $entity->id() . ' transition'));
     return $row + parent::buildRow($entity);
 }
 /**
  * Builds a row for an entity in the entity listing.
  *
  * @param EntityInterface $entity
  *   The entity for which to build the row.
  *
  * @return array
  *   A render array of the table row for displaying the entity.
  *
  * @see Drupal\Core\Entity\EntityListController::render()
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $entity->label();
     $row['machine_name'] = $entity->id();
     $row['floopy'] = $entity->floopy;
     return $row + parent::buildRow($entity);
 }
예제 #22
0
 /**
  * {@inheritdoc}
  */
 public function getTitle()
 {
     // Title based on the entity label. Should be translated for display in the
     // current page language. The title placeholder is later escaped for
     // display.
     $entity_type_info = $this->entityManager->getDefinition($this->entityType);
     return $this->t($this->pluginDefinition['title'], array('!label' => $this->entity->label(), '!entity_type' => $entity_type_info->getLowercaseLabel()));
 }
예제 #23
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /* @var $entity \Drupal\component\Entity\Component */
     $row['id'] = $entity->id();
     $row['name'] = $this->l($entity->label(), new Url('entity.component.canonical', array('component' => $entity->id())));
     $row['uuid'] = $entity->uuid();
     return $row + parent::buildRow($entity);
 }
예제 #24
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $entity->label();
     $row['id'] = $entity->id();
     $row['description'] = $entity->getDescription();
     $row['operations']['data'] = $this->buildOperations($entity);
     return $row;
 }
예제 #25
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var \Drupal\page_manager\PageInterface $entity */
     $row['label'] = $entity->label();
     $row['id'] = $entity->id();
     $row['path'] = $this->getPath($entity);
     return $row + parent::buildRow($entity);
 }
예제 #26
0
 /**
  * {@inheritdoc}
  */
 public function cloneEntity(EntityInterface $entity, EntityInterface $cloned_entity, $properties = []) {
   /** @var \Drupal\core\Entity\ContentEntityInterface $cloned_entity */
   if ($label_key = $this->entityTypeManager->getDefinition($this->entityTypeId)->getKey('label')) {
     $cloned_entity->set($label_key, $entity->label() . ' - Cloned');
   }
   $cloned_entity->save();
   return $cloned_entity;
 }
 /**
  * Builds a row for an entity in the entity listing.
  *
  * @param EntityInterface $entity
  *   The entity for which to build the row.
  *
  * @return array
  *   A render array of the table row for displaying the entity.
  *
  * @see Drupal\Core\Entity\EntityListController::render()
  */
 public function buildRow(EntityInterface $entity)
 {
     $row['label'] = $entity->label();
     $row['machine_name'] = $entity->id();
     $row['description'] = $entity->get('description');
     $row['source_type'] = $entity->get('source_type');
     return $row + parent::buildRow($entity);
 }
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $medium_editor)
 {
     $row['label'] = $medium_editor->label();
     $row['description'] = String::checkPlain($medium_editor->get('description'));
     $row['toolbar'] = String::checkPlain(implode(', ', $medium_editor->getToolbar()));
     $row['delay'] = String::checkPlain($medium_editor->get('delay'));
     return $row + parent::buildRow($medium_editor);
 }
예제 #29
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row = array();
     $row['label']['data'] = array('#type' => 'link', '#title' => SafeMarkup::checkPlain($entity->label()), '#url' => $entity->urlInfo());
     $row['type'] = SafeMarkup::checkPlain($entity->get('type')->entity->label());
     $row['changed'] = $this->dateFormatter->format($entity->get('changed')->value, 'short');
     return $row + parent::buildRow($entity);
 }
예제 #30
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     $row = array();
     $row['date']['data'] = $entity->get('activity_date')->view(array('label' => 'hidden'));
     $row['title']['data'] = array('#type' => 'link', '#title' => SafeMarkup::checkPlain($entity->label()), '#url' => $entity->urlInfo());
     $row['type'] = $entity->get('type')->entity->label();
     return $row + parent::buildRow($entity);
 }