本文整理汇总了PHP中Drupal::l方法的典型用法代码示例。如果您正苦于以下问题:PHP Drupal::l方法的具体用法?PHP Drupal::l怎么用?PHP Drupal::l使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal
的用法示例。
在下文中一共展示了Drupal::l方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPopularContentBlock
/**
* Tests the "popular content" block.
*/
function testPopularContentBlock()
{
// Clear the block cache to load the Statistics module's block definitions.
$this->container->get('plugin.manager.block')->clearCachedDefinitions();
// Visit a node to have something show up in the block.
$node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->blockingUser->id()));
$this->drupalGet('node/' . $node->id());
// Manually calling statistics.php, simulating ajax behavior.
$nid = $node->id();
$post = http_build_query(array('nid' => $nid));
$headers = array('Content-Type' => 'application/x-www-form-urlencoded');
global $base_url;
$stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
$client = \Drupal::service('http_client_factory')->fromOptions(['config/curl' => [CURLOPT_TIMEOUT => 10]]);
$client->post($stats_path, array('headers' => $headers, 'body' => $post));
// Configure and save the block.
$this->drupalPlaceBlock('statistics_popular_block', array('label' => 'Popular content', 'top_day_num' => 3, 'top_all_num' => 3, 'top_last_num' => 3));
// Get some page and check if the block is displayed.
$this->drupalGet('user');
$this->assertText('Popular content', 'Found the popular content block.');
$this->assertText("Today's", "Found today's popular content.");
$this->assertText('All time', 'Found the all time popular content.');
$this->assertText('Last viewed', 'Found the last viewed popular content.');
// statistics.module doesn't use node entities, prevent the node language
// from being added to the options.
$this->assertRaw(\Drupal::l($node->label(), $node->urlInfo('canonical', ['language' => NULL])), 'Found link to visited node.');
}
示例2: overview
/**
* {@inheritdoc}
*/
public function overview()
{
$content = array();
$content['description'] = array('#markup' => t('This displays a list of all Mailchimp Subscription Fields
configured on your system, with a row for each unique Instance of that field.
To edit each field\'s settings, go to the Entity Bundle\'s configuration
screen and use the Field UI.
When entities with MailChimp Subscription Fields are updated,
the Merge Variables configured through Field UI are automatically updated if necessary.
However, if you have existing subscribers on MailChimp and matching Entities
on Drupal when you configure your Merge Variables, the existing values
are not synced automatically, as this could be a slow process.
You can manually force updates of all existing Merge Values to existing
MailChimp subscribers for each field configuration using the \'Batch Update\'
option on this table. The MailChimp Subscription Field is provided by the
Mailchimp Lists (mailchimp_lists) module.'));
$content['fields_table'] = array('#type' => 'table', '#header' => array(t('Entity Type'), t('Bundle'), t('Field'), t('Batch Update')), '#empty' => '');
$field_map = \Drupal::entityManager()->getFieldMap();
$row_id = 1;
foreach ($field_map as $entity_type => $fields) {
foreach ($fields as $field_name => $field_properties) {
if ($field_properties['type'] == 'mailchimp_lists_subscription') {
foreach ($field_properties['bundles'] as $bundle) {
$batch_update_url = Url::fromRoute('mailchimp_lists.update_mergevars', array('entity_type' => $entity_type, 'bundle' => $bundle, 'field_name' => $field_name, 'destination' => 'admin/config/services/mailchimp/fields'));
$content['fields_table'][$row_id]['entity_type'] = array('#markup' => $entity_type);
$content['fields_table'][$row_id]['bundle'] = array('#markup' => $bundle);
$content['fields_table'][$row_id]['field'] = array('#markup' => $field_name);
$content['fields_table'][$row_id]['batch_update'] = array('#markup' => \Drupal::l(t('Update Mailchimp Mergevar Values'), $batch_update_url));
$row_id++;
}
}
}
}
return $content;
}
示例3: view
/**
* {@inheritdoc}
*/
public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)
{
$build = parent::view($entity, $view_mode, $langcode);
// Attach campaign JS and CSS.
$build['#attached']['library'][] = 'mailchimp_campaign/campaign-view';
// Prepare rendered content.
/* @var $entity \Drupal\mailchimp_campaign\Entity\MailchimpCampaign */
$content = $this->renderTemplate($entity->getTemplate());
$rendered = '';
foreach ($content as $key => $section) {
$rendered .= "<h3>{$key}</h3>" . $section;
}
// Get the template name.
$mc_template = mailchimp_campaign_get_template($entity->mc_data['template_id']);
$mc_template_name = isset($mc_template) ? $mc_template['name'] : '';
$list_segment_name = 'N/A';
$list_segments = mailchimp_campaign_get_list_segments($entity->list['id'], 'saved');
if (isset($entity->mc_data['saved_segment']['id'])) {
foreach ($list_segments as $list_segment) {
if ($list_segment['id'] == $entity->mc_data['saved_segment']['id']) {
$list_segment_name = $list_segment['name'];
}
}
}
$list_url = Url::fromUri('https://admin.mailchimp.com/lists/dashboard/overview?id=' . $entity->list['web_id'], array('attributes' => array('target' => '_blank')));
$archive_url = Url::fromUri($entity->mc_data['archive_url']);
$fields = array('subject' => array('label' => t('Subject'), 'value' => $entity->mc_data['subject']), 'list' => array('label' => t('MailChimp List'), 'value' => \Drupal::l($entity->list['name'], $list_url)), 'list_segment' => array('label' => t('List Segment'), 'value' => $list_segment_name), 'from_email' => array('label' => t('From Email'), 'value' => $entity->mc_data['from_email']), 'from_name' => array('label' => t('From Name'), 'value' => $entity->mc_data['from_name']), 'template' => array('label' => t('Template'), 'value' => $mc_template_name), 'type' => array('label' => t('List type'), 'value' => $entity->mc_data['type']), 'status' => array('label' => t('Status'), 'value' => $entity->mc_data['status']), 'emails_sent' => array('label' => t('Emails sent'), 'value' => $entity->mc_data['emails_sent']), 'send_time' => array('label' => t('Send time'), 'value' => $entity->mc_data['send_time']), 'content' => array('label' => t('Rendered template HTML (!archive)', array('!archive' => \Drupal::l('View MailChimp archive', $archive_url, array('attributes' => array('target' => '_blank'))))), 'value' => $rendered));
foreach ($fields as $key => $field) {
$build[$key] = array('#prefix' => "<div class=\"field campaign-{$key}\"><h3 class=\"field-label\">{$field['label']}</h3>", '#markup' => "<p>{$field['value']}</p>", '#suffix' => '</div>');
}
return $build;
}
示例4: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\oauth2_server\Entity\ClientEntity */
$row['id'] = $entity->id();
$row['server'] = \Drupal::l($this->getLabel($entity), new Url('entity.oauth2_server_client.edit_form', array('oauth2_server_client' => $entity->id())));
return $row + parent::buildRow($entity);
}
示例5: buildRow
/**
* {@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);
}
示例6: render
/**
* Adds some descriptive text to our entity list.
*
* @return array
* Renderable array.
*/
public function render()
{
$build['description'] = array('#markup' => $this->t("<p>This is a list of the countries currently" . " defined for use on your Drupal site. This country data adheres to" . " the @iso standard for country and zone naming used by payment" . " providers and package couriers.</p>" . "<p>To make a country available for use at checkout or in a user's" . " address book, 'Enable' the country using the widget in the" . " 'Operations' for that country. You may also 'Disable' a country to" . " prevent customers from selecting that country as a billing or" . " shipping address.</p>" . "<p>You may also use the 'Edit' widget in the 'Operations' column to" . " edit a country's name or address format.</p>", ['@iso' => \Drupal::l('ISO 3166', Url::fromUri('http://en.wikipedia.org/wiki/ISO_3166'))]));
$build += parent::render();
$build['table']['#empty'] = $this->t('No countries have been configured yet.');
return $build;
}
示例7: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\brand\Entity\brand */
$row['id'] = $entity->id();
$row['name'] = \Drupal::l($this->getLabel($entity), new Url('entity.brand.edit_form', array('brand' => $entity->id())));
return $row + parent::buildRow($entity);
}
示例8: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\eck\Entity\EckEntity */
$row['id'] = $entity->id();
$row['title'] = \Drupal::l($this->getLabel($entity), Url::fromRoute('entity.' . $this->entityTypeId . '.canonical', array($this->entityTypeId => $entity->id())));
return array_merge($row, parent::buildRow($entity));
}
示例9: settingsForm
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state)
{
$url = Url::fromRoute('autofloat.settings');
$config_link = \Drupal::l(t('AutoFloat Filter Settings'), $url);
$form['notice'] = array('#markup' => t('!config_link are shared by all the text formats where it is enabled.', array('!config_link' => $config_link)));
return $form;
}
示例10: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\my_first_entity\Entity\Course */
$row['id'] = $entity->id();
$row['name'] = \Drupal::l($this->getLabel($entity), new Url('entity.course.edit_form', array('course' => $entity->id())));
return $row + parent::buildRow($entity);
}
示例11: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
global $base_url;
$block_url = Url::fromRoute('block.admin_display');
$page_url = Url::fromUri($base_url . '/' . $entity->settings['path']);
$modes = NULL;
$mc_lists = mailchimp_get_lists();
switch ($entity->mode) {
case MAILCHIMP_SIGNUP_BLOCK:
$modes = \Drupal::l(t('Block'), $block_url);
$block_only = TRUE;
break;
case MAILCHIMP_SIGNUP_PAGE:
$modes = \Drupal::l(t('Page'), $page_url);
break;
case MAILCHIMP_SIGNUP_BOTH:
$modes = \Drupal::l(t('Block'), $block_url) . ' and ' . \Drupal::l(t('Page'), $page_url);
break;
}
$list_labels = array();
foreach ($entity->mc_lists as $list_id) {
if (!empty($list_id)) {
$list_url = Url::fromUri('https://admin.mailchimp.com/lists/dashboard/overview?id=' . $mc_lists[$list_id]['web_id'], array('attributes' => array('target' => '_blank')));
$list_labels[] = \Drupal::l($mc_lists[$list_id]['name'], $list_url);
}
}
$row['label'] = $this->getLabel($entity) . ' (Machine name: ' . $entity->id() . ')';
$row['display_modes'] = $modes;
$row['lists'] = implode(', ', $list_labels);
return $row + parent::buildRow($entity);
}
示例12: testIntegration
/**
* Tests the integration.
*/
public function testIntegration()
{
// Remove the watchdog entries added by the potential batch process.
$this->container->get('database')->truncate('watchdog')->execute();
$entries = array();
// Setup a watchdog entry without tokens.
$entries[] = array('message' => $this->randomMachineName(), 'variables' => array('link' => \Drupal::l('Link', new Url('<front>'))));
// Setup a watchdog entry with one token.
$entries[] = array('message' => '@token1', 'variables' => array('@token1' => $this->randomMachineName(), 'link' => \Drupal::l('Link', new Url('<front>'))));
// Setup a watchdog entry with two tokens.
$entries[] = array('message' => '@token1 !token2', 'variables' => array('@token1' => $this->randomMachineName(), '!token2' => $this->randomMachineName(), 'link' => \Drupal::l(SafeMarkup::set('<object>Link</object>'), new Url('<front>'))));
$logger_factory = $this->container->get('logger.factory');
foreach ($entries as $entry) {
$entry += array('type' => 'test-views', 'severity' => RfcLogLevel::NOTICE);
$logger_factory->get($entry['type'])->log($entry['severity'], $entry['message'], $entry['variables']);
}
$view = Views::getView('test_dblog');
$this->executeView($view);
$view->initStyle();
foreach ($entries as $index => $entry) {
$this->assertEqual($view->style_plugin->getField($index, 'message'), SafeMarkup::format($entry['message'], $entry['variables']));
$this->assertEqual($view->style_plugin->getField($index, 'link'), Xss::filterAdmin($entry['variables']['link']));
}
// Disable replacing variables and check that the tokens aren't replaced.
$view->destroy();
$view->storage->invalidateCaches();
$view->initHandlers();
$this->executeView($view);
$view->initStyle();
$view->field['message']->options['replace_variables'] = FALSE;
foreach ($entries as $index => $entry) {
$this->assertEqual($view->style_plugin->getField($index, 'message'), $entry['message']);
}
}
示例13: listOfMembers
/**
* Render a list of entries in the database.
*/
public function listOfMembers($grouping)
{
$content = array();
$content['add_existing_member'] = $this->formBuilder()->getForm('\\Drupal\\ea_grouping_members\\EAGroupingMembersAddForm', $grouping);
$content['add_new_member'] = $this->formBuilder()->getForm('\\Drupal\\ea_people\\EAPeopleAddForm');
$content['message'] = array('#markup' => $this->t('Generate a list of all members of the grouping.'));
$header = array(array('data' => $this->t('Nickname'), 'field' => 'person.nickname'), array('data' => $this->t('First name'), 'field' => 'person.firstname'), array('data' => $this->t('Last names'), 'field' => 'person.lastnames'), $this->t('Edit'), $this->t('Membership'));
// Only show members of this grouping.
$filter = array('gid' => $grouping->gid);
// Construct table rows.
$rows = array();
foreach ($entries = EAGroupingMembersStorage::loadSorted($header, $filter) as $member) {
// Construct rows.
$row = array();
$row['data']['nickname'] = $member->nickname;
$row['data']['firstname'] = $member->firstname;
$row['data']['lastnames'] = $member->lastnames;
// Format edit link.
$edit_link_url = Url::fromRoute('ea_grouping_members.edit', array('grouping' => $grouping->gid, 'member' => $member->gmid));
$edit_link = \Drupal::l($this->t('Edit'), $edit_link_url);
$row['data']['edit_link'] = $edit_link;
// Format cancel link.
$cancel_link_url = Url::fromRoute('ea_grouping_members.cancel', array('grouping' => $grouping->gid, 'member' => $member->gmid));
$cancel_link = \Drupal::l($this->t('Cancel'), $cancel_link_url);
$row['data']['cancel_link'] = $cancel_link;
// Add data to row.
$rows[] = $row;
}
$content['table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => t('No members added yet.'));
$content['pager'] = array('#type' => 'pager');
return $content;
}
示例14: viewElements
/**
* {@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;
}
示例15: build
/**
* {@inheritdoc}
*/
public function build()
{
$settings = $this->getConfiguration();
if (!empty($settings)) {
/** @var EntityInterface $entity */
$entity = $this->entity();
// Basic route parameters
$route_parameters = array('entityType' => $entity->getEntityTypeId(), 'entityId' => $entity->id());
$selector = $this->viewMode() == 'default' ? 'full' : $this->viewMode();
// Basic route options
$route_options = array('query' => array('selector' => 'view-mode-' . $selector), 'attributes' => array('class' => array('use-ajax')));
foreach ($settings['vms'] as $key => $value) {
// If the label is empty, do not create a link
if (!empty($value)) {
$route_parameters['viewMode'] = $key == 'default' ? 'full' : $key;
$items[] = \Drupal::l($value, Url::fromRoute('ds_extras.switch_view_mode', $route_parameters, $route_options));
}
}
}
$output = array();
if (!empty($items)) {
$output = array('#theme' => 'item_list', '#items' => $items, '#attached' => array('library' => array('core/drupal.ajax')));
}
return $output;
}