コード例 #1
1
ファイル: TermReference.php プロジェクト: geodesfour/dp741
 /**
  * {@inheritdoc}
  */
 function fieldFindCandidate(array $items)
 {
     $terms = array();
     foreach ($items as $item) {
         $terms[$item['tid']] = TRUE;
     }
     if (count($terms) > 1) {
         $walk = $terms;
         $visited = array();
         while (!empty($walk)) {
             $visited += $walk;
             foreach ($walk as $tid => $true) {
                 $parents = taxonomy_get_parents($tid);
                 unset($walk[$tid]);
                 foreach ($parents as $parent_tid => $parent) {
                     unset($terms[$parent_tid]);
                     if (!isset($visited[$parent_tid])) {
                         $walk[$parent_tid] = $parent;
                     }
                 }
             }
         }
     }
     // Return the path of the first found term, if any.
     foreach ($terms as $tid => $term_info) {
         $term = taxonomy_term_load($tid);
         if (!empty($term)) {
             $uri = entity_uri('taxonomy_term', $term);
             if (!empty($uri)) {
                 return $uri['path'];
             }
         }
     }
     return NULL;
 }
コード例 #2
0
/**
 * Lets modules specify the path information expected by a uri callback.
 *
 * The Product module defines a uri callback for the product entity even though
 * it doesn't actually define any product menu items. The callback invokes this
 * hook and will return the first set of path information it finds. If the
 * Product UI module is enabled, it will alter the product entity definition to
 * use its own uri callback that checks commerce_product_uri() for a return
 * value and defaults to an administrative link defined by that module.
 *
 * This hook is used as demonstrated below by the Product Reference module to
 * direct modules to link the product to the page where it is actually displayed
 * to the user. Currently this is specific to nodes, but the system should be
 * beefed up to accommodate even non-entity paths.
 *
 * @param $product
 *   The product object whose uri information should be returned.
 *
 * @return
 *   Implementations of this hook should return an array of information as
 *   expected to be returned to entity_uri() by a uri callback function.
 *
 * @see commerce_product_uri()
 * @see entity_uri()
 */
function hook_commerce_product_uri($product)
{
    // If the product has a display context, use it entity_uri().
    if (!empty($product->display_context)) {
        return entity_uri($product->display_context['entity_type'], $product->display_context['entity']);
    }
}
コード例 #3
0
 /**
  * Uses drupal 7 API to generate the entity URL
  *
  * @param string $type
  * @param mixed $entity
  *
  * @return string
  */
 private function getDrupalEntityPath($type, $entity)
 {
     $uri = entity_uri($type, $entity);
     if (!$uri) {
         throw new \InvalidArgumentException(sprintf("%s: entity type is not supported yet"));
     }
     return $uri['path'];
 }
コード例 #4
0
/**
 * Process variables for comment.tpl.php.
 *
 * @see comment.tpl.php
 */
function unikue_preprocess_comment(&$variables)
{
    $comment = $variables['elements']['#comment'];
    $node = $variables['elements']['#node'];
    $variables['comment'] = $comment;
    $variables['node'] = $node;
    $variables['author'] = theme('username', array('account' => $comment));
    $variables['created'] = date('d F Y', $comment->created);
    // Avoid calling format_date() twice on the same timestamp.
    if ($comment->changed == $comment->created) {
        $variables['changed'] = $variables['created'];
    } else {
        $variables['changed'] = format_date($comment->changed);
    }
    $variables['new'] = !empty($comment->new) ? t('new') : '';
    $variables['picture'] = theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', array('account' => $comment)) : '';
    $variables['signature'] = $comment->signature;
    $uri = entity_uri('comment', $comment);
    $uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
    $variables['title'] = l($comment->subject, $uri['path'], $uri['options']);
    $variables['permalink'] = l(t('Permalink'), $uri['path'], $uri['options']);
    $variables['submitted'] = t('!username  on !datetime', array('!username' => $variables['author'], '!datetime' => date('d/m/Y', $comment->created)));
    // Preprocess fields.
    field_attach_preprocess('comment', $comment, $variables['elements'], $variables);
    // Helpful $content variable for templates.
    foreach (element_children($variables['elements']) as $key) {
        $variables['content'][$key] = $variables['elements'][$key];
    }
    // Set status to a string representation of comment->status.
    if (isset($comment->in_preview)) {
        $variables['status'] = 'comment-preview';
    } else {
        $variables['status'] = $comment->status == COMMENT_NOT_PUBLISHED ? 'comment-unpublished' : 'comment-published';
    }
    // Gather comment classes.
    // 'comment-published' class is not needed, it is either 'comment-preview' or
    // 'comment-unpublished'.
    if ($variables['status'] != 'comment-published') {
        $variables['classes_array'][] = $variables['status'];
    }
    if ($variables['new']) {
        $variables['classes_array'][] = 'comment-new';
    }
    if (!$comment->uid) {
        $variables['classes_array'][] = 'comment-by-anonymous';
    } else {
        if ($comment->uid == $variables['node']->uid) {
            $variables['classes_array'][] = 'comment-by-node-author';
        }
        if ($comment->uid == $variables['user']->uid) {
            $variables['classes_array'][] = 'comment-by-viewer';
        }
    }
    foreach ($variables['content']['links']['comment']['#links'] as $key => $value) {
        $variables['content']['links']['comment']['#links'][$key]['attributes']['class'] = array('button button-small');
    }
}
コード例 #5
0
 /**
  * @Route("/{entity_type}/{entity}", name="entity_view", defaults={"view_mode" = "full", "langcode" = null, "page" = null})
  * @Method("GET")
  * @ParamConverter("entity", converter="drupal.entity")
  * @Template
  */
 public function viewAction(Request $request, $entity_type, $entity)
 {
     $view_mode = $request->get('view_mode');
     $langcode = $request->get('langcode');
     $page = $request->get('page');
     list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
     $entities = entity_view($entity_type, array($id => $entity), $view_mode, $langcode, $page);
     return array('label' => entity_label($entity_type, $entity), 'uri' => entity_uri($entity_type, $entity), 'entity_type' => $entity_type, 'id' => $id, 'vid' => $vid, 'bundle' => $bundle, 'entity' => $entity, 'content' => reset($entities[$entity_type]));
 }
コード例 #6
0
ファイル: Artists__1_1.php プロジェクト: adam-s/954live
 public function formatGenres($genres)
 {
     $element = array();
     foreach ($genres as $delta => $resource) {
         $wrapper = $resource->getInterpreter()->getWrapper();
         $uri = entity_uri('taxonomy_term', $wrapper->value());
         $element[$delta] = array('#type' => 'link', '#title' => $wrapper->name->value(), '#href' => $uri['path'], '#options' => $uri['options']);
     }
     return drupal_render($element);
 }
コード例 #7
0
ファイル: EntityReference.php プロジェクト: radicalsuz/fe
 /**
  * {@inheritdoc}
  */
 function fieldFindCandidate(array $items)
 {
     $field = $this->getFieldInfo();
     if ($target_type = $field['settings']['target_type']) {
         foreach ($items as $item) {
             if (1 && !empty($item['target_id']) && count($target_entities = entity_load($target_type, array($item['target_id']))) && ($uri = entity_uri($target_type, reset($target_entities)))) {
                 return $uri['path'];
             }
         }
     }
 }
コード例 #8
0
 public function handleEntity(array &$metadata = array())
 {
     $uri = entity_uri($this->original_entity->type(), $this->original_entity->definition);
     if (empty($uri['path'])) {
         return;
     }
     $redirects = redirect_load_multiple(false, array('redirect' => $uri['path']));
     foreach ($redirects as $index => $redirect) {
         $entity = new Entity($redirect, 'redirect');
         $this->addDependency($entity, false);
         $this->addDependency($this->original_entity, array($entity->uuid()));
     }
 }
コード例 #9
0
 public function genresProcess($tids)
 {
     $genres = taxonomy_term_load_multiple($tids);
     if (empty($genres)) {
         return NULL;
     }
     $element = [];
     foreach ($genres as $genre) {
         $path = entity_uri('taxonomy_term', $genre);
         $element[] = array('name' => entity_label('taxonomy_term', $genre), 'path' => url($path['path'], $path['options']));
     }
     return $element;
 }
コード例 #10
0
/**
 * Override or insert variables into the comment template.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 */
function gavias_laikafood_preprocess_comment(&$vars)
{
    $vars['title_attributes_array']['class'][] = 'comment-title';
    $vars['content_attributes_array']['class'][] = 'comment-content';
    $uri = entity_uri('comment', $vars['comment']);
    $uri['options'] += array('attributes' => array('rel' => 'bookmark'));
    $vars['title'] = l($vars['comment']->subject, $uri['path'], $uri['options']);
    $vars['permalink'] = l(t('Permalink'), $uri['path'], $uri['options']);
    $vars['created'] = '<span class="date-time permalink">' . l($vars['created'], $uri['path'], $uri['options']) . '</span>';
    $vars['datetime'] = format_date($vars['comment']->created, 'custom', 'c');
    $vars['unpublished'] = '';
    if ($vars['status'] == 'comment-unpublished') {
        $vars['unpublished'] = '<div class="unpublished">' . t('Unpublished') . '</div>';
    }
}
コード例 #11
0
 protected function _defaultDatasEntities($route = 'entities.json')
 {
     $options = $this->getOptions();
     $datas = array();
     foreach ($this->elements() as $entity) {
         $wrapper = entity_metadata_wrapper($options['entity-type'], $entity);
         $data = $this->dataModel($route);
         $data['id'] = $wrapper->getIdentifier();
         $data['url'] = call_user_func_array('url', entity_uri($options['entity-type'], $entity));
         $data['title'] = $wrapper->title->value();
         $data['body'] = $wrapper->body->value->value();
         $datas[] = $data;
     }
     return $datas;
 }
コード例 #12
0
 /**
  * Constructor for the Add to cart form. Provide $nid as the id of the
  * product display node. Other optional arguments are product reference field
  * name, view mode of the product display node and language of the product
  * display node. If optional arguments are not provided, their default values
  * are assumed, which are "field_product", "default" and "en" respectively.
  *
  * @param int $nid
  *   Product display node id.
  */
 public function __construct($nid)
 {
     $args = func_get_args();
     array_shift($args);
     $field_name = array_shift($args);
     $view_mode = array_shift($args);
     $language = array_shift($args);
     if (is_null($field_name)) {
         $field_name = 'field_product';
     }
     if (is_null($view_mode)) {
         $view_mode = 'default';
     }
     if (is_null($language)) {
         $language = 'en';
     }
     $node = node_load($nid);
     $instance = field_info_instance('node', $field_name, $node->type);
     $display = field_get_display($instance, $view_mode, $node);
     $settings = array_merge(field_info_formatter_settings($display['type']), $display['settings']);
     $field_product = field_get_items('node', $node, $field_name);
     $product_id = $field_product[0]['product_id'];
     $products = commerce_product_load_multiple(array($product_id));
     $type = !empty($settings['line_item_type']) ? $settings['line_item_type'] : 'product';
     $line_item = commerce_product_line_item_new(commerce_product_reference_default_product($products), $settings['default_quantity'], 0, array(), $type);
     $line_item->data['context']['product_ids'] = array_keys($products);
     $line_item->data['context']['add_to_cart_combine'] = !empty($settings['combine']);
     $line_item->data['context']['show_single_product_attributes'] = !empty($settings['show_single_product_attributes']);
     $cart_context = array('entity_type' => 'node', 'entity_id' => $nid, 'display' => 'default', 'language' => $language);
     $cart_context['class_prefix'] = $cart_context['entity_type'] . '-' . $nid;
     $cart_context['view_mode'] = $cart_context['entity_type'] . '_' . $view_mode;
     $entity_uri = entity_uri($cart_context['entity_type'], $node);
     $arguments = array('form_id' => commerce_cart_add_to_cart_form_id(array($product_id)), 'line_item' => $line_item, 'show_quantity' => $settings['show_quantity']);
     // Add the display path and referencing entity data to the line item.
     if (!empty($entity_uri['path'])) {
         $arguments['line_item']->data['context']['display_path'] = $entity_uri['path'];
     }
     $arguments['line_item']->data['context']['entity'] = array('entity_type' => $cart_context['entity_type'], 'entity_id' => $cart_context['entity_id'], 'product_reference_field_name' => $field_name);
     // Update the product_ids variable to point to the entity data if we're
     // referencing multiple products.
     if (count($arguments['line_item']->data['context']['product_ids']) > 1) {
         $arguments['line_item']->data['context']['product_ids'] = 'entity';
     }
     parent::__construct($arguments['form_id'], $arguments['line_item'], $arguments['show_quantity'], $cart_context);
     $this->cart_context = $cart_context;
     $this->arguments = $arguments;
 }
コード例 #13
0
 public function render($results)
 {
     $social = NULL;
     if ($this->wrapper->field_social->value()[0]['url']) {
         $social = $this->wrapper->field_social->value()[0]['url'];
     }
     $uri = entity_uri('node', $this->wrapper->value());
     $path = drupal_get_path_alias($uri['path']);
     // ld+json microdata URLs are absolute
     $address = $this->wrapper->field_address->value();
     $geo = $this->wrapper->field_geo->value();
     $output = array('@type' => 'MusicVenue', "@context" => "http://schema.org", 'name' => $this->wrapper->title->value(), 'description' => $this->wrapper->field_about->value(), 'image' => file_create_url($this->wrapper->field_image->value()['uri']), 'sameAs' => $social, 'telephone' => $this->wrapper->field_phone->value(), 'url' => url($path, array('absolute' => TRUE)), 'address' => array('@type' => 'PostalAddress', "@context" => "http://schema.org", 'streetAddress' => $address['thoroughfare'], 'addressLocality' => $address['locality'], 'addressRegion' => $address['administrative_area'], 'postalCode' => $address['postal_code']), 'geo' => array('@type' => 'GeoCoordinates', "@context" => "http://schema.org", 'latitude' => $geo['lat'], 'longitude' => $geo['lon']));
     $output['event'] = $this->eventJSON($results);
     $element = array('#type' => 'markup', '#markup' => '<script type="application/ld+json">' . json_encode($output) . "</script>");
     // json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
     drupal_add_html_head($element, 'livesource_jsonld');
 }
コード例 #14
0
 /**
  * {@inheritdoc}
  */
 public function hookTokens($type, $tokens, array $data = array(), array $options = array())
 {
     $replacements = array();
     if ($this->isValidTokenType($type)) {
         foreach ($tokens as $name => $original) {
             if ($this->isValidToken($original)) {
                 $render = array();
                 $entity_id = $this->getEntityIdFromToken($original);
                 $entity_type = $type == 'term' ? 'taxonomy_term' : $type;
                 $entity_info = entity_get_info($entity_type);
                 $entity = $entity_info['load hook']($entity_id);
                 $uri = entity_uri($entity_type, $entity);
                 $replacements[$original] = url($uri['path'], array('absolute' => TRUE));
             }
         }
     }
     return $replacements;
 }
コード例 #15
0
ファイル: send.php プロジェクト: sammarks/publisher
function action_feedback()
{
    $transaction = TransactionSession::getFromSession();
    if (!$transaction) {
        return t('There was an error processing the entities.');
    }
    // Before marking the transaction session as complete, set the title.
    action_feedback_title();
    // Set the forced flag based on if any of the root entites were forced.
    $forced = false;
    $root_entity_ids = array();
    foreach ($transaction->getRootEntities() as $uuid => $root_entity) {
        $root_entity_ids[] = $uuid;
        if (array_key_exists('force', $root_entity['options']) && $root_entity['options']['force']) {
            $forced = true;
            break;
        }
    }
    // Add each of the entities to the list for the form.
    $form_entities = array();
    foreach ($transaction->getAllEntities() as $dependency) {
        if (!array_key_exists('original_dependency', $dependency)) {
            continue;
        }
        $original_dependency = $dependency['original_dependency'];
        $form_entity = array();
        $entity = \Drupal\publisher\Entity::loadByUUID($dependency['entity_uuid'], $dependency['entity_type']);
        $entity_uri = entity_uri($entity->type(), $entity->definition);
        $entity_path = ltrim($entity_uri['path'], '/');
        $form_entity['label'] = l(entity_label($entity->type(), $entity->definition), $entity_path) . ' [<strong>' . $entity->type() . '</strong> <code>' . $entity->id() . '</code>]';
        $form_entity['required'] = $original_dependency['required'];
        $form_entity['required_if'] = $original_dependency['required_if'];
        $form_entity['entity_type'] = $dependency['entity_type'];
        $form_entity['root_entity'] = in_array($dependency['entity_uuid'], $root_entity_ids);
        $form_entities[$dependency['entity_uuid']] = $form_entity;
    }
    // If there are no entities to move, complete the session.
    if (count($form_entities) <= 0) {
        $transaction->complete();
    }
    // Output each of the entities to the page with their status.
    $form = drupal_get_form('publisher_select_entities_form', $form_entities, 'publisher_action_feedback_entities_selected', $forced, $transaction->getRemote());
    return $form;
}
コード例 #16
0
 /**
  * Save a scheduled transition. If the transition is executed, save as logged transition.
  */
 public function save()
 {
     // If executed, save as logged transition.
     if ($this->is_executed) {
         return parent::save();
     }
     // Avoid duplicate entries.
     $this->delete();
     // Save (insert or update) a record to the database based upon the schema.
     drupal_write_record('workflow_scheduled_transition', $this);
     // Get name of state.
     if ($state = WorkflowState::load($this->new_sid)) {
         $message = '@entity_title scheduled for state change to %state_name on %scheduled_date';
         $args = array('@entity_type' => $this->entity_type, '@entity_title' => $this->entity->title, '%state_name' => $state->label(), '%scheduled_date' => format_date($this->scheduled));
         $uri = entity_uri($this->entity_type, $this->entity);
         watchdog('workflow', $message, $args, WATCHDOG_NOTICE, l('view', $uri['path'] . '/workflow'));
         drupal_set_message(t($message, $args));
     }
 }
コード例 #17
0
ファイル: Genres__1_0.php プロジェクト: adam-s/954live
 public function termProcess($term)
 {
     // Graciously borrowed from function taxonomy_field_formatter_view in taxonomy.module
     $uri = entity_uri('taxonomy_term', $term);
     $element = array('#type' => 'link', '#title' => $term->name, '#href' => $uri['path'], '#options' => $uri['options']);
     if (!isset($element['#options']['attributes'])) {
         $element['#options']['attributes'] = array();
     }
     // Found at function rdf_field_attach_view_alter in rdf.module
     if (!empty($term->rdf_mapping['rdftype'])) {
         $element['#options']['attributes']['typeof'] = $term->rdf_mapping['rdftype'];
     }
     if (!empty($term->rdf_mapping['name']['predicates'])) {
         // A property attribute is used with an empty datatype attribute so
         // the term name is parsed as a plain literal in RDFa 1.0 and 1.1.
         $element['#options']['attributes']['property'] = $term->rdf_mapping['name']['predicates'];
         $element['#options']['attributes']['datatype'] = '';
     }
     return drupal_render($element);
 }
コード例 #18
0
 public function render($results)
 {
     $social = NULL;
     if ($this->wrapper->field_social->value()[0]['url']) {
         $social = $this->wrapper->field_social->value()[0]['url'];
     }
     $genres = array();
     foreach ($this->wrapper->field_genres->value() as $genre) {
         $genres[] = $genre->name;
     }
     $title = $this->wrapper->title->value();
     $about = $this->wrapper->field_about->value();
     $uri = entity_uri('node', $this->wrapper->value());
     $image_uri = $this->wrapper->field_image->value()['uri'];
     $output = array('@type' => 'MusicGroup', "@context" => "http://schema.org", 'name' => $title, 'description' => $about, 'url' => url($uri['path'], array('absolute' => TRUE)), 'sameAs' => $social, 'image' => file_create_url($image_uri), 'genre' => $genres);
     if (!empty($results)) {
         $output['event'] = $this->eventJSON($results);
     }
     $element = array('#type' => 'markup', '#markup' => '<script type="application/ld+json">' . json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "</script>");
     drupal_add_html_head($element, 'livesource_jsonld');
 }
コード例 #19
0
ファイル: SessionForm.php プロジェクト: sammarks/publisher
 public function build($form, &$form_state)
 {
     $headers = array('Entity');
     $rows = array();
     $transaction = TransactionSession::getFromSession();
     if ($transaction !== false) {
         $remote = $transaction->getRemote();
         $root_entities = $transaction->getRootEntities();
         $form['current_session'] = array('#type' => 'fieldset', '#title' => t('Current Session'));
         $form['current_session']['remote'] = array('#type' => 'html_tag', '#tag' => 'p', '#value' => t('Currently sending <strong>!count</strong> entities to <strong>:remote</strong>', array('!count' => count($root_entities), ':remote' => $remote->label)));
         foreach ($root_entities as $root_entity) {
             /** @var Entity $entity */
             $entity = $root_entity['entity'];
             $uri = entity_uri($entity->type(), $entity->definition);
             $url = ltrim($uri['path'], '/');
             $rows[] = array(l(entity_label($entity->type(), $entity->definition), $url));
         }
         $form['current_session']['clear'] = array('#type' => 'submit', '#value' => 'Clear Session');
     }
     $form['table'] = array('#theme' => 'table', '#header' => $headers, '#rows' => $rows, '#empty' => t('There is currently no pending publisher session.'));
     return $form;
 }
コード例 #20
0
 protected function overviewTableRow($conditions, $id, $entity, $additional_cols = array())
 {
     $entity_uri = entity_uri($this->entityType, $entity);
     $row[] = array('data' => array('#theme' => 'entity_ui_overview_item', '#label' => entity_label($this->entityType, $entity), '#name' => !empty($this->entityInfo['exportable']) ? entity_id($this->entityType, $entity) : FALSE, '#url' => $entity_uri ? $entity_uri : FALSE, '#entity_type' => $this->entityType));
     // Add in any passed additional cols.
     foreach ($additional_cols as $col) {
         $row[] = $col;
     }
     // Add a row for the exportable status.
     if (!empty($this->entityInfo['exportable'])) {
         $row[] = array('data' => array('#theme' => 'entity_status', '#status' => $entity->{$this->statusKey}));
     }
     // In case this is a bundle, we add links to the field ui tabs.
     $field_ui = !empty($this->entityInfo['bundle of']) && entity_type_is_fieldable($this->entityInfo['bundle of']) && module_exists('field_ui');
     // For exportable entities we add an export link.
     $exportable = !empty($this->entityInfo['exportable']);
     // If i18n integration is enabled, add a link to the translate tab.
     $i18n = !empty($this->entityInfo['i18n controller class']);
     // Add operations depending on the status.
     if (entity_has_status($this->entityType, $entity, ENTITY_FIXED)) {
         $row[] = array('data' => l(t('clone'), $this->path . '/manage/' . $id . '/clone'), 'colspan' => $this->operationCount());
     } else {
         $row[] = l(t('edit'), $this->path . '/manage/' . $id);
         if (empty($this->entityInfo['exportable']) || !entity_has_status($this->entityType, $entity, ENTITY_IN_CODE)) {
             $row[] = l(t('delete'), $this->path . '/manage/' . $id . '/delete', array('query' => drupal_get_destination()));
         } else {
             $row[] = '';
         }
     }
     if ($exportable) {
         $row[] = l(t('export'), $this->path . '/manage/' . $id . '/export');
     }
     $row[] = $entity->product_quantity;
     $row[] = l(t('quick+1'), '/product/' . $id . '/add/1');
     $row[] = l(t('quick-1'), '/product/' . $id . '/sub/1');
     return $row;
 }
コード例 #21
0
 /**
  * {@inheritdoc}
  */
 public function hookTokens($type, $tokens, array $data = array(), array $options = array())
 {
     $replacements = array();
     if ($this->isValidTokenType($type)) {
         foreach ($tokens as $name => $original) {
             if ($this->isValidToken($original)) {
                 $entity_id = $this->getEntityIdFromToken($original);
                 $entity_type = $type == 'term' ? 'taxonomy_term' : $type;
                 $entity_info = entity_get_info($entity_type);
                 // Check if the entity is available.
                 if ($entity = $entity_info['load hook']($entity_id)) {
                     $label = entity_label($entity_type, $entity);
                     $uri = entity_uri($entity_type, $entity);
                     $replacements[$original] = l($label, $uri['path'], array('absolute' => TRUE));
                 } else {
                     $this->watchdogTokenNotFound($data, $original);
                     // Return an empty replacement to not show a broken link.
                     $replacements[$original] = '';
                 }
             }
         }
     }
     return $replacements;
 }
コード例 #22
0
ファイル: template.php プロジェクト: orion76/drupal.ru
/**
 * Implements hook_preprocess_comment().
 */
function alpha_preprocess_comment(&$variables)
{
    $comment = $variables['elements']['#comment'];
    $variables['timeago'] = t('@time ago', array('@time' => format_interval(time() - $comment->changed)));
    $uri = entity_uri('comment', $comment);
    $variables['permalink'] = l('#', $uri['path'], $uri['options']);
}
コード例 #23
0
ファイル: node.tpl.php プロジェクト: chousmith/catshirts-d7
 * variables. Otherwise they will have to explicitly specify the desired field
 * language, e.g. $node->body['en'], thus overriding any language negotiation
 * rule that was previously applied.
 *
 * @see template_preprocess()
 * @see template_preprocess_node()
 * @see template_process()
 */
/* TWITTER CARD */
$hd = drupal_add_html_head();
$element = array('#tag' => 'meta', '#attributes' => array('name' => 'twitter:card', 'content' => 'photo'));
drupal_add_html_head($element, 'tw_1_card');
global $base_url;
$uri = array('path' => '');
if ($node != false) {
    $uri = entity_uri('node', $node);
}
$element = array('#tag' => 'meta', '#attributes' => array('name' => 'twitter:url', 'content' => url($uri['path'], array('absolute' => true))));
drupal_add_html_head($element, 'tw_4_url');
$element = array('#tag' => 'meta', '#attributes' => array('name' => 'twitter:domain', 'content' => url('', array('absolute' => true))));
drupal_add_html_head($element, 'tw_4_domain');
$element = array('#tag' => 'meta', '#attributes' => array('name' => 'twitter:creator', 'content' => '@chousmith'));
drupal_add_html_head($element, 'tw_2_creator');
$element = array('#tag' => 'meta', '#attributes' => array('name' => 'twitter:site', 'content' => '@chousmith'));
drupal_add_html_head($element, 'tw_3_site');
$twtitle = str_replace('again: ', '', $title);
$element = array('#tag' => 'meta', '#attributes' => array('name' => 'twitter:title', 'content' => $twtitle));
$hd = drupal_add_html_head($element, 'tw_5_title');
if (isset($node->field_image)) {
    if (isset($node->field_image['und'])) {
        $imgpath = image_style_url('l480640', $node->field_image['und'][0]['uri']);
コード例 #24
0
ファイル: template.php プロジェクト: Frantsuzzz/drupal.ru
/**
 * Implements hook_preprocess_comment().
 */
function alpha_preprocess_comment(&$variables)
{
    drupal_add_js(drupal_get_path('theme', 'alpha') . '/js/' . 'comment-action-slide.js');
    $comment = $variables['elements']['#comment'];
    $variables['timeago'] = t('@time ago', array('@time' => format_interval(time() - $comment->changed)));
    $uri = entity_uri('comment', $comment);
    $variables['permalink'] = l('#', $uri['path'], $uri['options']);
    if (isset($variables['content']['links']['comment']['#links']['comment_forbidden'])) {
        unset($variables['content']['links']['comment']['#links']['comment_forbidden']);
    }
    // We need to make sure that we have links.
    // If we don't have links we do not display icon "***".
    if (!empty($variables['content']['links']['comment']['#links'])) {
        $variables['content']['links']['comment']['#links']['#cid'] = $comment->cid;
    }
}
コード例 #25
0
ファイル: AddThis.php プロジェクト: tasfya/maktaba
 public function getDisplayMarkup($display, $options = array())
 {
     if (empty($display)) {
         return array();
     }
     $formatters = _addthis_field_info_formatter_field_type();
     if (!array_key_exists($display, $formatters)) {
         return array();
     }
     // The display type exists. Now get it and get the markup.
     $display_information = $formatters[$display];
     // Theme function might only give a display name and
     // render on default implementation.
     if (!isset($options['#display']) || isset($options['#display']['type']) && $options['#display']['type'] != $display) {
         $options['#display'] = isset($options['#display']) ? $options['#display'] : array();
         $options['#display'] = array_merge($options['#display'], $display_information);
         $options['#display']['type'] = $display;
     }
     // When #entity and #entity_type exist, use the entity's URL.
     if (isset($options['#entity']) && isset($options['#entity_type'])) {
         $uri = entity_uri($options['#entity_type'], $options['#entity']);
         $uri['options'] += array('absolute' => TRUE);
         // @todo Add a hook to alter the uri also based on fields from the
         // entity (such as custom share link). Pass $options and $uri. Return
         // a uri object to which we can reset it. Maybe use the alter structure.
         $options['#url'] = url($uri['path'], $uri['options']);
     }
     // @todo Hash the options array and cache the markup.
     // This will save all the extra calls to modules and alters.
     // Allow other modules to alter markup options.
     drupal_alter('addthis_markup_options', $options);
     $markup = array('#display' => $options['#display']);
     // Get all hook implementation to verify later if we can call it.
     $addthis_display_markup_implementations = module_implements('addthis_display_markup');
     // Look for a targeted implementation to call.
     // This should be the default implementation that is called.
     if (function_exists($display_information['module'] . '_addthis_display_markup__' . $display)) {
         $markup += call_user_func_array($display_information['module'] . '_addthis_display_markup__' . $display, array($options));
     } elseif (in_array($display_information['module'], $addthis_display_markup_implementations)) {
         $markup += module_invoke($display_information['module'], 'addthis_display_markup', $display, $options);
     }
     // Allow other modules to alter markup.
     drupal_alter('addthis_markup', $markup);
     return $markup;
 }
コード例 #26
0
/**
 * Override or insert variables into the comment templates.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("comment" in this case.)
 */
function STARTERKIT_preprocess_comment(&$variables, $hook)
{
    // Change the permalink to just use the created date.
    $comment = $variables['elements']['#comment'];
    $uri = entity_uri('comment', $comment);
    $uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
    $variables['permalink'] = l(format_date($comment->created, 'custom', 'F j, Y'), $uri['path'], $uri['options']);
}
コード例 #27
0
 /**
  * Builds a reverse menu trail for the entity.
  *
  * @param object $data
  *   An entity object.
  */
 function buildReverseMenuTrail($data)
 {
     $vars = array();
     $output = '';
     $uri = entity_uri($this->plugin['entity_type'], $data);
     if (isset($uri['path'])) {
         $menu_link_fields = array('link_title', 'link_path', 'plid', 'menu_name');
         $menu_items = db_select('menu_links', 'ml')->fields('ml', $menu_link_fields)->condition('link_path', $uri['path'])->execute()->fetchAll(PDO::FETCH_ASSOC);
         foreach ($menu_items as $menu_item) {
             $vars['reverse_menu_trail'] = array();
             while ($menu_item['plid']) {
                 $menu_item = db_select('menu_links', 'ml')->fields('ml', $menu_link_fields)->condition('mlid', $menu_item['plid'])->execute()->fetchAssoc();
                 if (isset($menu_item['link_title'])) {
                     $vars['reverse_menu_trail'][] = $menu_item['link_title'];
                 }
             }
             $output .= !empty($vars['reverse_menu_trail']) ? theme('linkit_reverse_menu_trail', $vars) : '';
         }
     }
     return $output;
 }
コード例 #28
0
 /**
  * Create an uri for an entity.
  *
  * @param $entity
  *   The entity to get the path from.
  *
  * @return
  *   A string containing the path of the entity, NULL if the entity has no
  *   uri of its own.
  */
 function createPath($entity)
 {
     // Create the URI for the entity.
     $uri = entity_uri($this->plugin['entity_type'], $entity);
     $options = array();
     // Handle multilingual sites.
     if (isset($entity->language) && $entity->language != LANGUAGE_NONE && drupal_multilingual() && language_negotiation_get_any(LOCALE_LANGUAGE_NEGOTIATION_URL)) {
         $languages = language_list('enabled');
         // Only use enabled languages.
         $languages = $languages[1];
         if ($languages && isset($languages[$entity->language])) {
             $options['language'] = $languages[$entity->language];
         }
     }
     // Process the uri with the insert pluing.
     $path = linkit_get_insert_plugin_processed_path($this->profile, $uri['path'], $options);
     return $path;
 }
コード例 #29
0
ファイル: Events__1_4.php プロジェクト: adam-s/954live
 public function uriProcess($entity)
 {
     $uri = entity_uri('node', $entity);
     $path = drupal_get_path_alias($uri['path']);
     return url($path);
 }
コード例 #30
0
ファイル: template.php プロジェクト: clashmusic/clash_zen
/**
 * 
 * Alter comments
 */
function clash_zen_preprocess_comment(&$variables)
{
    $comment = $variables['elements']['#comment'];
    // Reformat username and date
    $uri = entity_uri('comment', $comment);
    $uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark', 'title' => 'Permalink'));
    $date_link = l(format_date($comment->created, 'clash_comments_date'), $uri['path'], $uri['options']);
    $variables['submitted'] = t('!username !datetime', array('!username' => $variables['author'], '!datetime' => $date_link));
    unset($variables['content']['links']['comment']['#links']['comment_forbidden']);
}