Пример #1
3
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = array();
     $settings = $this->getSettings();
     $items_array = array();
     foreach ($items as $item) {
         $items_array[] = $item;
     }
     // Merge defaults from the formatters and ensure proper ordering.
     $this->prepareFormatters($this->fieldDefinition->getType(), $settings['formatters']);
     // Loop through each formatter in order.
     foreach ($settings['formatters'] as $name => $options) {
         // Run any unrendered items through the formatter.
         $formatter_items = array_diff_key($items_array, $element);
         $formatter_instance = $this->getFormatter($options);
         $formatter_instance->prepareView(array($items->getEntity()->id() => $items));
         if ($result = $formatter_instance->viewElements($items, $langcode)) {
             // Only add visible content from the formatter's render array result
             // that matches an unseen delta.
             $visible_deltas = Element::getVisibleChildren($result);
             $visible_deltas = array_intersect($visible_deltas, array_keys($formatter_items));
             $element += array_intersect_key($result, array_flip($visible_deltas));
             // If running this formatter completed the output for all items, then
             // there is no need to loop through the rest of the formatters.
             if (count($element) == count($items_array)) {
                 break;
             }
         }
     }
     // Ensure the resulting elements are ordered properly by delta.
     ksort($element);
     return $element;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = [];
     if ($items->status == 1 && $this->currentUser->hasPermission('view disqus comments')) {
         $element[] = ['#type' => 'disqus', '#url' => $items->getEntity()->toUrl('canonical', ['absolute' => TRUE])->toString(), '#title' => (string) $items->getEntity()->label(), '#identifier' => $items->identifier ?: "{$items->getEntity()->getEntityTypeId()}/{$items->getEntity()->id()}"];
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL)
 {
     // Fields that are not implicitly allowed to administrative users.
     $explicit_check_fields = array('pass');
     // Administrative users are allowed to edit and view all fields.
     if (!in_array($field_definition->getName(), $explicit_check_fields) && $account->hasPermission('administer users')) {
         return AccessResult::allowed()->cachePerPermissions();
     }
     // Flag to indicate if this user entity is the own user account.
     $is_own_account = $items ? $items->getEntity()->id() == $account->id() : FALSE;
     switch ($field_definition->getName()) {
         case 'name':
             // Allow view access to anyone with access to the entity. Anonymous
             // users should be able to access the username field during the
             // registration process, otherwise the username and email constraints
             // are not checked.
             if ($operation == 'view' || $items && $account->isAnonymous() && $items->getEntity()->isAnonymous()) {
                 return AccessResult::allowed()->cachePerPermissions();
             }
             // Allow edit access for the own user name if the permission is
             // satisfied.
             if ($is_own_account && $account->hasPermission('change own username')) {
                 return AccessResult::allowed()->cachePerPermissions()->cachePerUser();
             } else {
                 return AccessResult::forbidden();
             }
         case 'preferred_langcode':
         case 'preferred_admin_langcode':
         case 'timezone':
         case 'mail':
             // Allow view access to own mail address and other personalization
             // settings.
             if ($operation == 'view') {
                 return $is_own_account ? AccessResult::allowed()->cachePerUser() : AccessResult::forbidden();
             }
             // Anyone that can edit the user can also edit this field.
             return AccessResult::allowed()->cachePerPermissions();
         case 'pass':
             // Allow editing the password, but not viewing it.
             return $operation == 'edit' ? AccessResult::allowed() : AccessResult::forbidden();
         case 'created':
             // Allow viewing the created date, but not editing it.
             return $operation == 'view' ? AccessResult::allowed() : AccessResult::forbidden();
         case 'roles':
         case 'status':
         case 'access':
         case 'login':
         case 'init':
             return AccessResult::forbidden();
     }
     return parent::checkFieldAccess($operation, $field_definition, $account, $items);
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = [];
     // As the Field API only applies the "field default value" to newly created
     // entities, we'll apply the default value for existing entities.
     if ($items->count() == 0) {
         $field_default_value = $items->getFieldDefinition()->getDefaultValue($items->getEntity());
         $items->status = $field_default_value[0]['status'];
     }
     if ($items->status == 1 && $this->currentUser->hasPermission('view disqus comments')) {
         $element[] = ['#type' => 'disqus', '#url' => $items->getEntity()->toUrl('canonical', ['absolute' => TRUE])->toString(), '#title' => (string) $items->getEntity()->label(), '#identifier' => $items->identifier ?: "{$items->getEntity()->getEntityTypeId()}/{$items->getEntity()->id()}"];
     }
     return $element;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode = NULL)
 {
     $elements = array();
     // This field should be on a comment.
     // Get the entity type of the entity this comment is attached to.
     $entityType = $items->getEntity()->get('entity_type')->value;
     foreach ($items as $delta => $item) {
         if (!empty($item->right_rid)) {
             $storage = \Drupal::entityManager()->getStorage($entityType);
             $right_revision = $storage->loadRevision($item->right_rid);
             $entity = $storage->load($right_revision->id());
             if (!empty($item->left_rid)) {
                 // We have a pair of revisions
                 $left_revision = $storage->loadRevision($item->left_rid);
                 $plugin = $this->diffLayoutManager->createInstance('changes');
                 $elements[$delta] = $plugin->build($left_revision, $right_revision, $entity);
             } else {
                 // We have just a single revision, the original of this entity.
                 // Only link to it if it is not the current revision.
                 if ($item->right_rid !== $entity->getRevisionId()) {
                     // Trigger exclusion of interactive items like on preview.
                     $right_revision->in_preview = TRUE;
                     $view_builder = \Drupal::entityTypeManager()->getViewBuilder($entityType);
                     $original = $view_builder->view($right_revision);
                     $elements[$delta] = ['#type' => 'details', '#title' => 'Original version'];
                     $elements[$delta]['original'] = $original;
                 }
             }
         }
     }
     return $elements;
 }
 /**
  * {@inheritdoc}
  */
 public function generateFieldMetadata(FieldItemListInterface $items, $view_mode)
 {
     $entity = $items->getEntity();
     $field_name = $items->getFieldDefinition()->getName();
     // Early-return if user does not have access.
     $access = $this->accessChecker->accessEditEntityField($entity, $field_name);
     if (!$access) {
         return array('access' => FALSE);
     }
     // Early-return if no editor is available.
     $formatter_id = EntityViewDisplay::collectRenderDisplay($entity, $view_mode)->getRenderer($field_name)->getPluginId();
     $editor_id = $this->editorSelector->getEditor($formatter_id, $items);
     if (!isset($editor_id)) {
         return array('access' => FALSE);
     }
     // Gather metadata, allow the editor to add additional metadata of its own.
     $label = $items->getFieldDefinition()->getLabel();
     $editor = $this->editorManager->createInstance($editor_id);
     $metadata = array('label' => String::checkPlain($label), 'access' => TRUE, 'editor' => $editor_id, 'aria' => t('Entity @type @id, field @field', array('@type' => $entity->getEntityTypeId(), '@id' => $entity->id(), '@field' => $label)));
     $custom_metadata = $editor->getMetadata($items);
     if (count($custom_metadata)) {
         $metadata['custom'] = $custom_metadata;
     }
     return $metadata;
 }
 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     // Shows the "default fields" in the edit-type-field page, AND edit-fields on the article-edit-page
     /** @var \Drupal\iframe\Plugin\Field\FieldType\IframeItem $item */
     $item = $items[$delta];
     $field_settings = $this->getFieldSettings();
     $settings = $this->getSettings();
     $settings += $field_settings;
     $entity = $items->getEntity();
     # pre fill with other attributes, (! last chance here !)
     if (TRUE) {
         # $entity->isNew() ?
         foreach (self::defaultSettings() as $dkey => $dval) {
             $ddval = isset($item->{$dkey}) ? $item->{$dkey} : (isset($settings[$dkey]) ? $settings[$dkey] : NULL);
             $element[$dkey] = array('#type' => 'value', '#value' => is_null($ddval) ? NULL : (string) $ddval);
         }
     }
     $title = isset($item->title) ? $item->title : (!empty($settings['title']) ? $settings['title'] : '');
     $element['title'] = array('#type' => 'textfield', '#title' => t('IFrame Title'), '#placeholder' => '', '#default_value' => $title, '#size' => 80, '#maxlength' => 1024, '#weight' => 2);
     $url = isset($item->url) && !empty($item->url) ? $item->url : (!empty($settings['url']) ? $settings['url'] : '');
     $element['url'] = array('#type' => 'textfield', '#title' => t('IFrame URL'), '#placeholder' => 'http://', '#default_value' => $url, '#size' => 80, '#maxlength' => 1024, '#weight' => 1);
     $width = isset($item->width) && !empty($item->width) ? $item->width : (isset($settings['width']) ? $settings['width'] : NULL);
     $element['width'] = array('#title' => t('width of an iframe'), '#type' => 'textfield', '#default_value' => $width, '#description' => t('iframes need fix width and height, only numbers are allowed.'), '#maxlength' => 4, '#size' => 4, '#weight' => 3, '#required' => TRUE);
     $height = isset($item->height) && !empty($item->height) ? $item->height : (isset($settings['height']) ? $settings['height'] : NULL);
     $element['height'] = array('#type' => 'textfield', '#title' => t('height of an iframe'), '#default_value' => $height, '#description' => t('iframes need fix width and height, only numbers are allowed.'), '#maxlength' => 4, '#size' => 4, '#weight' => 4, '#required' => TRUE);
     if ($settings['expose_class']) {
         $element['class'] = array('#type' => 'textfield', '#title' => t('Additional CSS Class'), '#default_value' => isset($item->class) ? $item->class : NULL, '#description' => t('When output, this iframe will have this class attribute. Multiple classes should be separated by spaces.'), '#weight' => 5);
     }
     #$element['#title'] = 'IIfframe';
     return $element;
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $field_settings = $this->getFieldSettings();
     // The field settings include defaults for the field type. However, this
     // widget is a base class for other widgets (e.g., ImageWidget) that may act
     // on field types without these expected settings.
     $field_settings += array('display_default' => NULL, 'display_field' => NULL, 'description_field' => NULL);
     $cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
     $defaults = array('fids' => array(), 'display' => (bool) $field_settings['display_default'], 'description' => '');
     // Essentially we use the managed_file type, extended with some
     // enhancements.
     $element_info = $this->elementInfo->getInfo('embridge_asset');
     $element += array('#type' => 'embridge_asset', '#upload_location' => $items[$delta]->getUploadLocation(), '#upload_validators' => $items[$delta]->getUploadValidators(), '#value_callback' => array(get_class($this), 'value'), '#process' => array_merge($element_info['#process'], array(array(get_class($this), 'process'))), '#progress_indicator' => $this->getSetting('progress_indicator'), '#extended' => TRUE, '#entity_type' => $items->getEntity()->getEntityTypeId(), '#field_name' => $this->fieldDefinition->getName(), '#field_config' => $this->fieldDefinition->id(), '#allow_search' => $field_settings['allow_search'], '#display_field' => (bool) $field_settings['display_field'], '#display_default' => $field_settings['display_default'], '#description_field' => $field_settings['description_field'], '#cardinality' => $cardinality, '#catalog_id' => $field_settings['catalog_id'], '#library_id' => $field_settings['library_id']);
     $element['#weight'] = $delta;
     // Field stores FID value in a single mode, so we need to transform it for
     // form element to recognize it correctly.
     if (!isset($items[$delta]->fids) && isset($items[$delta]->target_id)) {
         $items[$delta]->fids = array($items[$delta]->target_id);
     }
     $element['#default_value'] = $items[$delta]->getValue() + $defaults;
     $default_fids = $element['#extended'] ? $element['#default_value']['fids'] : $element['#default_value'];
     if (empty($default_fids)) {
         $file_upload_help = array('#theme' => 'file_upload_help', '#description' => $element['#description'], '#upload_validators' => $element['#upload_validators'], '#cardinality' => $cardinality);
         $this->alterFileUploadHelpParameters($file_upload_help);
         $element['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
         $element['#multiple'] = $cardinality != 1 ? TRUE : FALSE;
         if ($cardinality != 1 && $cardinality != -1) {
             $element['#element_validate'] = array(array(get_class($this), 'validateMultipleCount'));
         }
     }
     return $element;
 }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $element = array();
     $entity = $items->getEntity();
     $settings = $this->getSettings();
     foreach ($items as $delta => $item) {
         // By default use the full URL as the link text.
         $url = $this->buildUrl($item);
         $link_title = $url->toString();
         // If the link text field value is available, use it for the text.
         if (empty($settings['url_only']) && !empty($item->title)) {
             // Unsanitized token replacement here because $options['html'] is FALSE
             // by default in l().
             $link_title = \Drupal::token()->replace($item->title, array($entity->getEntityTypeId() => $entity), array('sanitize' => FALSE, 'clear' => TRUE));
         }
         // The link_separate formatter has two titles; the link text (as in the
         // field values) and the URL itself. If there is no link text value,
         // $link_title defaults to the URL, so it needs to be unset.
         // The URL version may need to be trimmed as well.
         if (empty($item->title)) {
             $link_title = NULL;
         }
         $url_title = $url->toString();
         if (!empty($settings['trim_length'])) {
             $link_title = truncate_utf8($link_title, $settings['trim_length'], FALSE, TRUE);
             $url_title = truncate_utf8($url_title, $settings['trim_length'], FALSE, TRUE);
         }
         $element[$delta] = array('#theme' => 'link_formatter_link_separate', '#title' => $link_title, '#url_title' => $url_title, '#url' => $url);
     }
     return $element;
 }
Пример #10
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $element = array();
     $entity = $items->getEntity();
     $settings = $this->getSettings();
     foreach ($items as $delta => $item) {
         // By default use the full URL as the link text.
         $url = $this->buildUrl($item);
         $link_title = $url->toString();
         // If the title field value is available, use it for the link text.
         if (empty($settings['url_only']) && !empty($item->title)) {
             // Unsanitized token replacement here because $options['html'] is FALSE
             // by default in l().
             $link_title = \Drupal::token()->replace($item->title, array($entity->getEntityTypeId() => $entity), array('sanitize' => FALSE, 'clear' => TRUE));
         }
         // Trim the link text to the desired length.
         if (!empty($settings['trim_length'])) {
             $link_title = truncate_utf8($link_title, $settings['trim_length'], FALSE, TRUE);
         }
         if (!empty($settings['url_only']) && !empty($settings['url_plain'])) {
             $element[$delta] = array('#markup' => String::checkPlain($link_title));
         } else {
             $element[$delta] = array('#type' => 'link', '#title' => $link_title, '#options' => $url->getOptions());
             if ($url->isExternal()) {
                 $element[$delta]['#href'] = $url->getPath();
             } else {
                 $element[$delta]['#route_name'] = $url->getRouteName();
                 $element[$delta]['#route_parameters'] = $url->getRouteParameters();
             }
         }
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  *
  * TODO: Use $langcode.
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = array();
     $settings = $this->getFieldSettings();
     $count = 0;
     // TODO: Is there a better way to get an accurate count of the
     // items from the FieldItemList that doesn't count blank items?
     // Possibly \Countable->count()?
     $storage = \Drupal::entityTypeManager()->getStorage('field_collection_item');
     foreach ($items as $delta => $item) {
         if ($item->value !== NULL) {
             $count++;
             $field_collection_item = $storage->loadRevision($item->revision_id);
             if ($field_collection_item->isDefaultRevision()) {
                 $links = \Drupal::l($this->fieldDefinition->getName() . ' ' . $delta, Url::FromRoute('entity.field_collection_item.canonical', array('field_collection_item' => $item->value)));
                 $links .= ' ' . $this->getEditLinks($item);
             } else {
                 $links = \Drupal::l($this->fieldDefinition->getName() . ' ' . $delta, Url::FromRoute('field_collection_item.revision_show', ['field_collection_item' => $item->value, 'field_collection_item_revision' => $item->revision_id]));
             }
             $element[$delta] = array('#markup' => $links);
         }
     }
     $cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
     if ($cardinality == -1 || $count < $cardinality) {
         $element['#suffix'] = '<ul class="action-links action-links-field-collection-add"><li>';
         $element['#suffix'] .= $this->getAddLink($items->getEntity());
         $element['#suffix'] .= '</li></ul>';
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $elements = [];
     if ($items->getEntity()->getEntityTypeId() == 'aggregator_feed') {
         $url_string = $items->getEntity()->getUrl();
     } else {
         $url_string = $items->getEntity()->getLink();
     }
     foreach ($items as $delta => $item) {
         if ($this->getSetting('display_as_link') && $url_string) {
             $elements[$delta] = ['#type' => 'link', '#title' => $item->value, '#url' => Url::fromUri($url_string)];
         } else {
             $elements[$delta] = ['#markup' => $item->value];
         }
     }
     return $elements;
 }
 /**
  * Generates unique ids for the field items.
  *
  * @param \Drupal\Core\Field\FieldItemListInterface $items
  *  The field items.
  * @return array
  *  Array of ids keyed by field item delta.
  */
 protected function generateIds(FieldItemListInterface $items)
 {
     $entity = $items->getEntity();
     $ids = array();
     foreach ($items as $delta => $item) {
         $ids[$delta] = implode('_', array($entity->getEntityTypeId(), $entity->bundle(), $entity->id(), $items->getFieldDefinition()->getName(), $delta));
     }
     return $ids;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $parent_entity = $items->getEntity();
     $elements = array();
     foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
         $parent_entity->rss_elements[] = array('key' => 'category', 'value' => $entity->label(), 'attributes' => array('domain' => $entity->id() ? \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $entity->id()], array('absolute' => TRUE)) : ''));
     }
     return $elements;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = array();
     $entity = $items->getEntity();
     foreach ($items as $item) {
         $entity->rss_elements[] = array('key' => 'category', 'value' => $item->entity->label(), 'attributes' => array('domain' => $item->target_id ? url('taxonomy/term/' . $item->target_id, array('absolute' => TRUE)) : ''));
     }
     return $elements;
 }
 /**
  * {@inheritdoc}
  */
 protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL)
 {
     if ($operation == 'edit') {
         // Only users with the "administer comments" permission can edit
         // administrative fields.
         $administrative_fields = array('uid', 'status', 'created', 'date');
         if (in_array($field_definition->getName(), $administrative_fields, TRUE)) {
             return AccessResult::allowedIfHasPermission($account, 'administer comments');
         }
         // No user can change read-only fields.
         $read_only_fields = array('hostname', 'changed', 'cid', 'thread');
         // These fields can be edited during comment creation.
         $create_only_fields = ['comment_type', 'uuid', 'entity_id', 'entity_type', 'field_name', 'pid'];
         if ($items && ($entity = $items->getEntity()) && $entity->isNew() && in_array($field_definition->getName(), $create_only_fields, TRUE)) {
             // We are creating a new comment, user can edit create only fields.
             return AccessResult::allowedIfHasPermission($account, 'post comments')->addCacheableDependency($entity);
         }
         // We are editing an existing comment - create only fields are now read
         // only.
         $read_only_fields = array_merge($read_only_fields, $create_only_fields);
         if (in_array($field_definition->getName(), $read_only_fields, TRUE)) {
             return AccessResult::forbidden();
         }
         // If the field is configured to accept anonymous contact details - admins
         // can edit name, homepage and mail. Anonymous users can also fill in the
         // fields on comment creation.
         if (in_array($field_definition->getName(), ['name', 'mail', 'homepage'], TRUE)) {
             if (!$items) {
                 // We cannot make a decision about access to edit these fields if we
                 // don't have any items and therefore cannot determine the Comment
                 // entity. In this case we err on the side of caution and prevent edit
                 // access.
                 return AccessResult::forbidden();
             }
             /** @var \Drupal\comment\CommentInterface $entity */
             $entity = $items->getEntity();
             $commented_entity = $entity->getCommentedEntity();
             $anonymous_contact = $commented_entity->get($entity->getFieldName())->getFieldDefinition()->getSetting('anonymous');
             $admin_access = AccessResult::allowedIfHasPermission($account, 'administer comments');
             $anonymous_access = AccessResult::allowedIf($entity->isNew() && $account->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT && $account->hasPermission('post comments'))->cachePerPermissions()->cacheUntilEntityChanges($entity)->cacheUntilEntityChanges($field_definition->getConfig($commented_entity->bundle()))->cacheUntilEntityChanges($commented_entity);
             return $admin_access->orIf($anonymous_access);
         }
     }
     if ($operation == 'view') {
         $entity = $items ? $items->getEntity() : NULL;
         // Admins can view any fields except hostname, other users need both the
         // "access comments" permission and for the comment to be published. The
         // mail field is hidden from non-admins.
         $admin_access = AccessResult::allowedIf($account->hasPermission('administer comments') && $field_definition->getName() != 'hostname')->cachePerPermissions();
         $anonymous_access = AccessResult::allowedIf($account->hasPermission('access comments') && (!$entity || $entity->isPublished()) && !in_array($field_definition->getName(), array('mail', 'hostname'), TRUE))->cachePerPermissions();
         if ($entity) {
             $anonymous_access->cacheUntilEntityChanges($entity);
         }
         return $admin_access->orIf($anonymous_access);
     }
     return parent::checkFieldAccess($operation, $field_definition, $account, $items);
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = array();
     $settings = $this->getSettings();
     foreach ($items as $delta => $item) {
         $element[$delta] = array('#theme' => 'youtube_video', '#video_id' => $item->video_id, '#entity_title' => $items->getEntity()->label(), '#settings' => $settings);
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $entity = $items->getEntity();
     // Add the first file as an enclosure to the RSS item. RSS allows only one
     // enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure
     foreach ($this->getEntitiesToView($items) as $delta => $file) {
         $entity->rss_elements[] = array('key' => 'enclosure', 'attributes' => array('url' => file_create_url($file->getFileUri()), 'length' => $file->getSize(), 'type' => $file->getMimeType()));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $entity = $items->getEntity();
     $referenced_entities = $items->referencedEntities();
     $element += array('#type' => 'entity_autocomplete', '#target_type' => $this->getFieldSetting('target_type'), '#selection_handler' => $this->getFieldSetting('handler'), '#selection_settings' => $this->getFieldSetting('handler_settings'), '#validate_reference' => FALSE, '#maxlength' => 1024, '#default_value' => isset($referenced_entities[$delta]) ? $referenced_entities[$delta] : NULL, '#size' => $this->getSetting('size'), '#placeholder' => $this->getSetting('placeholder'));
     if ($this->getSelectionHandlerSetting('auto_create')) {
         $element['#autocreate'] = array('bundle' => $this->getAutocreateBundle(), 'uid' => $entity instanceof EntityOwnerInterface ? $entity->getOwnerId() : \Drupal::currentUser()->id());
     }
     return array('target_id' => $element);
 }
 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $tags = array();
     if (!$items->isEmpty()) {
         foreach ($items as $item) {
             $tags[] = isset($item->entity) ? $item->entity : entity_load('taxonomy_term', $item->target_id);
         }
     }
     $element += array('#type' => 'textfield', '#default_value' => taxonomy_implode_tags($tags), '#autocomplete_route_name' => $this->getSetting('autocomplete_route_name'), '#autocomplete_route_parameters' => array('entity_type' => $items->getEntity()->getEntityTypeId(), 'field_name' => $this->fieldDefinition->getName()), '#size' => $this->getSetting('size'), '#placeholder' => $this->getSetting('placeholder'), '#maxlength' => 1024, '#element_validate' => array('taxonomy_autocomplete_validate'));
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $entity = $items->getEntity();
     // Prepare the autocomplete route parameters.
     $autocomplete_route_parameters = array('type' => $this->getSetting('autocomplete_type'), 'field_name' => $this->fieldDefinition->getName(), 'entity_type' => $entity->getEntityTypeId(), 'bundle_name' => $entity->bundle());
     if ($entity_id = $entity->id()) {
         $autocomplete_route_parameters['entity_id'] = $entity_id;
     }
     $element += array('#type' => 'textfield', '#maxlength' => 1024, '#default_value' => implode(', ', $this->getLabels($items, $delta)), '#autocomplete_route_name' => 'entity_reference.autocomplete', '#autocomplete_route_parameters' => $autocomplete_route_parameters, '#size' => $this->getSetting('size'), '#placeholder' => $this->getSetting('placeholder'), '#element_validate' => array(array($this, 'elementValidate')), '#autocreate_uid' => $entity instanceof EntityOwnerInterface ? $entity->getOwnerId() : \Drupal::currentUser()->id());
     return array('target_id' => $element);
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $elements = array();
     $link_setting = $this->getSetting('link_to');
     $entity = $items->getEntity();
     foreach ($this->getEntitiesToView($items, $langcode) as $delta => $asset) {
         $item = $asset->_referringItem;
         $elements[$delta] = array('#theme' => 'embridge_file_link', '#asset' => $asset, '#description' => $item->description, '#entity' => $entity, '#link_to' => $link_setting, '#cache' => array('tags' => $asset->getCacheTags()));
     }
     return $elements;
 }
Пример #23
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = array();
     $settings = $this->getSettings();
     foreach ($items as $delta => $item) {
         $element[$delta] = array('#theme' => 'youtube_video', '#video_id' => $item->video_id, '#entity_title' => $items->getEntity()->label(), '#settings' => $settings);
         if ($settings['youtube_size'] == 'responsive') {
             $element[$delta]['#attached']['library'][] = 'youtube/drupal.youtube.responsive';
         }
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode = NULL)
 {
     $element = array();
     $settings = $this->getSettings();
     $currency = \Drupal::config('stripe_checkout.settings')->get('stripe_checkout_currency');
     $description = '';
     if ($settings['stripe_checkout_description'] == 'title') {
         $description = $items->getEntity()->getTitle();
     } elseif ($settings['stripe_checkout_description'] != '') {
         // Get the value of the field specified by the display setting
         $field_items = $items->getEntity()->get($settings['stripe_checkout_description'])->getValue();
         foreach ($field_items as $item) {
             $description = $item['value'];
         }
     }
     $nid = $items->getEntity()->id();
     foreach ($items as $delta => $item) {
         $element[$delta] = array('#theme' => 'stripe_checkout_simple', '#description' => $description, '#amount' => $item->value, '#currency' => $settings['stripe_checkout_currency'] ? $settings['stripe_checkout_currency'] : $currency, '#nid' => $nid);
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $payment_line_items = new LineItemCollection();
     /** @var \Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemInterface $item */
     foreach ($items as $delta => $item) {
         $payment_line_items->setLineItem($item->getContainedPluginInstance());
     }
     $entity = $items->getEntity();
     if ($entity instanceof LineItemCollectionInterface) {
         $payment_line_items->setCurrencyCode($entity->getCurrencyCode());
     }
     $build[0] = array('#payment_line_items' => $payment_line_items, '#type' => 'payment_line_items_display');
     return $build;
 }
Пример #26
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = [];
     foreach ($items as $delta => $item) {
         $provider = $this->providerManager->loadProviderFromInput($item->value);
         $url = FALSE;
         if ($this->getSetting('link_image_to') == static::LINK_CONTENT) {
             $url = $items->getEntity()->urlInfo();
         } elseif ($this->getSetting('link_image_to') == static::LINK_PROVIDER) {
             $url = Url::fromUri($item->value);
         }
         $element[$delta] = $provider->renderThumbnail($this->getSetting('image_style'), $url);
     }
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 protected function getSelectedOptions(FieldItemListInterface $items, $delta = 0)
 {
     // Copy parent behavior but also check the status property.
     $flat_options = OptGroup::flattenOptions($this->getOptions($items->getEntity()));
     $selected_options = array();
     foreach ($items as $item) {
         $value = $item->{$this->column};
         // Keep the value if it actually is in the list of options (needs to be
         // checked against the flat list).
         if ($item->status == SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED && isset($flat_options[$value])) {
             $selected_options[] = $value;
         }
     }
     return $selected_options;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $entity = $items->getEntity();
     // Terms whose target_id is 'autocreate' do not exist yet and
     // $item->entity is not set. Theme such terms as just their name.
     foreach ($items as $item) {
         if ($item->target_id) {
             $value = $item->entity->label();
             $domain = $item->entity->url('canonical', array('absolute' => TRUE));
         } else {
             $value = $item->entity->label();
             $domain = '';
         }
         $entity->rss_elements[] = array('key' => 'category', 'value' => $value, 'attributes' => array('domain' => $domain));
     }
 }
Пример #29
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode) {
     $elements = array();
     foreach ($items as $delta => $item) {
         $entity = $items->getEntity();
         $elements[$delta] = array(
             '#type' => 'processed_text',
             '#text' => $item->value,
             '#format' => $item->format,
             '#langcode' => $item->getLangcode(),
             '#theme' => 'text_link_formatter',
             '#item' => $item,
             '#url' => $entity->urlInfo()
         );
     }
     return $elements;
 }
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items)
 {
     $elements = array();
     $entity = $items->getEntity();
     $allowed_values = options_allowed_values($this->fieldDefinition, $entity);
     foreach ($items as $delta => $item) {
         if (isset($allowed_values[$item->value])) {
             $output = field_filter_xss($allowed_values[$item->value]);
         } else {
             // If no match was found in allowed values, fall back to the key.
             $output = field_filter_xss($item->value);
         }
         $elements[$delta] = array('#markup' => $output);
     }
     return $elements;
 }