/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); /** @var \Drupal\commerce_tax\Entity\TaxTypeInterface $tax_type */ $tax_type = $this->entity; /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $zone_storage */ $zone_storage = $this->entityTypeManager->getStorage('zone'); $zones = $zone_storage->loadMultipleOverrideFree(); // @todo Filter by zone scope == 'tax'. $zones = array_map(function ($zone) { return $zone->label(); }, $zones); $form['name'] = ['#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $tax_type->getName(), '#maxlength' => 255, '#required' => TRUE]; $form['id'] = ['#type' => 'machine_name', '#title' => $this->t('Machine name'), '#default_value' => $tax_type->getId(), '#machine_name' => ['exists' => '\\Drupal\\commerce_tax\\Entity\\TaxType::load', 'source' => ['name']], '#required' => TRUE, '#disabled' => !$tax_type->isNew()]; $form['zone'] = ['#type' => 'select', '#title' => $this->t('Zone'), '#default_value' => $tax_type->getZoneId(), '#options' => $zones, '#required' => TRUE]; if ($tax_type->isNew()) { $link = Link::createFromRoute('Zones page', 'entity.zone.collection')->toString(); $form['zone']['#description'] = $this->t('To add a new zone visit the @link.', ['@link' => $link]); } $form['compound'] = ['#type' => 'checkbox', '#title' => $this->t('Compound'), '#description' => $this->t("Compound tax is calculated on top of a primary tax. For example, Canada's Provincial Sales Tax (PST) is compound, calculated on a price that already includes the Goods and Services Tax (GST)."), '#default_value' => $tax_type->isCompound()]; $form['displayInclusive'] = ['#type' => 'checkbox', '#title' => $this->t('Display inclusive'), '#default_value' => $tax_type->isDisplayInclusive()]; $form['roundingMode'] = ['#type' => 'radios', '#title' => $this->t('Rounding mode'), '#default_value' => $tax_type->getRoundingMode() ?: TaxType::ROUND_HALF_UP, '#options' => [TaxType::ROUND_HALF_UP => $this->t('Round up'), TaxType::ROUND_HALF_DOWN => $this->t('Round down'), TaxType::ROUND_HALF_EVEN => $this->t('Round even'), TaxType::ROUND_HALF_ODD => $this->t('Round odd')], '#required' => TRUE]; $form['tag'] = ['#type' => 'textfield', '#title' => $this->t('Tag'), '#description' => $this->t('Used by the resolvers to analyze only the tax types relevant to them. For example, the EuTaxTypeResolver would analyze only the tax types with the "EU" tag.'), '#default_value' => $tax_type->getTag()]; return $form; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $book_nids = array(); $links = array(Link::createFromRoute($this->t('Home'), '<front>')); $book = $route_match->getParameter('node')->book; $depth = 1; // We skip the current node. while (!empty($book['p' . ($depth + 1)])) { $book_nids[] = $book['p' . $depth]; $depth++; } $parent_books = $this->nodeStorage->loadMultiple($book_nids); if (count($parent_books) > 0) { $depth = 1; while (!empty($book['p' . ($depth + 1)])) { if (!empty($parent_books[$book['p' . $depth]]) && ($parent_book = $parent_books[$book['p' . $depth]])) { if ($parent_book->access('view', $this->account)) { $links[] = Link::createFromRoute($parent_book->label(), 'entity.node.canonical', array('node' => $parent_book->id())); } } $depth++; } } return $links; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $book_nids = array(); $breadcrumb = new Breadcrumb(); $links = array(Link::createFromRoute($this->t('Home'), '<front>')); $book = $route_match->getParameter('node')->book; $depth = 1; // We skip the current node. while (!empty($book['p' . ($depth + 1)])) { $book_nids[] = $book['p' . $depth]; $depth++; } $parent_books = $this->nodeStorage->loadMultiple($book_nids); if (count($parent_books) > 0) { $depth = 1; while (!empty($book['p' . ($depth + 1)])) { if (!empty($parent_books[$book['p' . $depth]]) && ($parent_book = $parent_books[$book['p' . $depth]])) { $access = $parent_book->access('view', $this->account, TRUE); $breadcrumb->addCacheableDependency($access); if ($access->isAllowed()) { $breadcrumb->addCacheableDependency($parent_book); $links[] = Link::createFromRoute($parent_book->label(), 'entity.node.canonical', array('node' => $parent_book->id())); } } $depth++; } } $breadcrumb->setLinks($links); $breadcrumb->addCacheContexts(['route.book_navigation']); return $breadcrumb; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = new Breadcrumb(); $breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>')); $term = $route_match->getParameter('taxonomy_term'); // Breadcrumb needs to have terms cacheable metadata as a cacheable // dependency even though it is not shown in the breadcrumb because e.g. its // parent might have changed. $breadcrumb->addCacheableDependency($term); // @todo This overrides any other possible breadcrumb and is a pure // hard-coded presumption. Make this behavior configurable per // vocabulary or term. $parents = $this->termStorage->loadAllParents($term->id()); // Remove current term being accessed. array_shift($parents); foreach (array_reverse($parents) as $term) { $term = $this->entityManager->getTranslationFromContext($term); $breadcrumb->addCacheableDependency($term); $breadcrumb->addLink(Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id()))); } // This breadcrumb builder is based on a route parameter, and hence it // depends on the 'route' cache context. $breadcrumb->addCacheContexts(['route']); return $breadcrumb; }
/** * Tests ForumBreadcrumbBuilderBase::build(). * * @see \Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase::build() * * @covers ::build */ public function testBuild() { // Build all our dependencies, backwards. $forum_manager = $this->getMockBuilder('Drupal\\forum\\ForumManagerInterface')->disableOriginalConstructor()->getMock(); $prophecy = $this->prophesize('Drupal\\taxonomy\\VocabularyInterface'); $prophecy->label()->willReturn('Fora_is_the_plural_of_forum'); $prophecy->id()->willReturn(5); $prophecy->getCacheTags()->willReturn(['taxonomy_vocabulary:5']); $prophecy->getCacheContexts()->willReturn([]); $prophecy->getCacheMaxAge()->willReturn(Cache::PERMANENT); $vocab_storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface'); $vocab_storage->expects($this->any())->method('load')->will($this->returnValueMap(array(array('forums', $prophecy->reveal())))); $entity_manager = $this->getMockBuilder('Drupal\\Core\\Entity\\EntityManagerInterface')->disableOriginalConstructor()->getMock(); $entity_manager->expects($this->any())->method('getStorage')->will($this->returnValueMap(array(array('taxonomy_vocabulary', $vocab_storage)))); $config_factory = $this->getConfigFactoryStub(array('forum.settings' => array('vocabulary' => 'forums'))); // Build a breadcrumb builder to test. $breadcrumb_builder = $this->getMockForAbstractClass('Drupal\\forum\\Breadcrumb\\ForumBreadcrumbBuilderBase', array($entity_manager, $config_factory, $forum_manager)); // Add a translation manager for t(). $translation_manager = $this->getStringTranslationStub(); $breadcrumb_builder->setStringTranslation($translation_manager); // Our empty data set. $route_match = $this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface'); // Expected result set. $expected = array(Link::createFromRoute('Home', '<front>'), Link::createFromRoute('Fora_is_the_plural_of_forum', 'forum.index')); // And finally, the test. $breadcrumb = $breadcrumb_builder->build($route_match); $this->assertEquals($expected, $breadcrumb->getLinks()); $this->assertEquals(['route'], $breadcrumb->getCacheContexts()); $this->assertEquals(['taxonomy_vocabulary:5'], $breadcrumb->getCacheTags()); $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge()); }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb[] = Link::createFromRoute($this->t('Home'), '<front>'); $vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($this->config->get('vocabulary')); $breadcrumb[] = Link::createFromRoute($vocabulary->label(), 'forum.index'); return $breadcrumb; }
/** * {@inheritdoc} */ public function build() { $options = array('attributes' => array('title' => $this->link_label())); return array('#type' => 'link', '#title' => $this->link_label(), '#url' => new Url('happy_alexandrie.query_welcome_controller', array(), $options), '#prefix' => '<p>', '#suffix' => '</p>'); // Other ways to do it. Directly using the link element. return [Link::createFromRoute($this->configuration['link_title'], 'happy_alexandrie.query_welcome_controller')->toRenderable()]; }
/** * Displays links to all products that have not been categorized. * * @return * Renderable form array. */ public function orphans() { $build = array(); if ($this->config('taxonomy.settings')->get('maintain_index_table')) { $vid = $this->config('uc_catalog.settings')->get('vocabulary'); $product_types = uc_product_types(); $field = FieldStorageConfig::loadByName('node', 'taxonomy_catalog'); //@todo - figure this out // $field is a config object, not an array, so this doesn't work. //$types = array_intersect($product_types, $field['bundles']['node']); $types = $product_types; //temporary to get this to work at all $result = db_query('SELECT DISTINCT n.nid, n.title FROM {node_field_data} n LEFT JOIN (SELECT ti.nid, td.vid FROM {taxonomy_index} ti LEFT JOIN {taxonomy_term_data} td ON ti.tid = td.tid WHERE td.vid = :vid) txnome ON n.nid = txnome.nid WHERE n.type IN (:types[]) AND txnome.vid IS NULL', [':vid' => $vid, ':types[]' => $types]); $rows = array(); while ($node = $result->fetchObject()) { $rows[] = Link::createFromRoute($node->title, 'entity.node.edit_form', ['node' => $node->nid], ['query' => ['destination' => 'admin/store/products/orphans']])->toString(); } if (count($rows) > 0) { $build['orphans'] = array('#theme' => 'item_list', '#items' => $rows); } else { $build['orphans'] = array('#markup' => $this->t('All products are currently listed in the catalog.'), '#prefix' => '<p>', '#suffix' => '</p>'); } } else { $build['orphans'] = array('#markup' => $this->t('The node terms index is not being maintained, so Ubercart can not determine which products are not entered into the catalog.'), '#prefix' => '<p>', '#suffix' => '</p>'); } return $build; }
/** * {@inheritdoc} */ public function view(OrderInterface $order, $view_mode) { $build = array('#type' => 'table', '#attributes' => array('class' => array('order-pane-table')), '#header' => array('qty' => array('data' => $this->t('Quantity'), 'class' => array('qty')), 'product' => array('data' => $this->t('Product'), 'class' => array('product')), 'model' => array('data' => $this->t('SKU'), 'class' => array('sku', RESPONSIVE_PRIORITY_LOW)), 'cost' => array('data' => $this->t('Cost'), 'class' => array('cost', RESPONSIVE_PRIORITY_LOW)), 'price' => array('data' => $this->t('Price'), 'class' => array('price')), 'total' => array('data' => $this->t('Total'), 'class' => array('price'))), '#empty' => $this->t('This order contains no products.')); $account = \Drupal::currentUser(); if (!$account->hasPermission('administer products')) { unset($build['#header']['cost']); } // @todo Replace with Views. foreach ($order->products as $id => $product) { $build[$id]['qty'] = array('#theme' => 'uc_qty', '#qty' => $product->qty->value, '#cell_attributes' => array('class' => array('qty'))); if ($product->nid->entity && $product->nid->entity->access('view')) { $title = Link::createFromRoute($product->title->value, 'entity.node.canonical', ['node' => $product->nid->target_id])->toString(); } else { $title = $product->title->value; } $build[$id]['product'] = array('#markup' => $title . uc_product_get_description($product), '#cell_attributes' => array('class' => array('product'))); $build[$id]['model'] = array('#markup' => $product->model->value, '#cell_attributes' => array('class' => array('sku'))); if ($account->hasPermission('administer products')) { $build[$id]['cost'] = array('#theme' => 'uc_price', '#price' => $product->cost->value, '#cell_attributes' => array('class' => array('cost'))); } $build[$id]['price'] = array('#theme' => 'uc_price', '#price' => $product->price->value, '#suffixes' => array(), '#cell_attributes' => array('class' => array('price'))); $build[$id]['total'] = array('#theme' => 'uc_price', '#price' => $product->price->value * $product->qty->value, '#suffixes' => array(), '#cell_attributes' => array('class' => array('total'))); // $build[$id][$field]['#wrapper_attributes']['class'] = $build['#header'][$field]['class']; } return $build; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = array(); $breadcrumb[] = Link::createFromRoute($this->t('Home'), '<front>'); $entity = $route_match->getParameter('entity'); $breadcrumb[] = new Link($entity->label(), $entity->urlInfo()); return $breadcrumb; }
/** * @inheritdoc */ public function build(RouteMatchInterface $route_match) { $breadcrumb = new Breadcrumb(); $geocoder = $route_match->getParameter('service'); $current_route = $route_match->getRouteName(); $links = [Link::createFromRoute($this->t('Home'), '<front>'), Link::createFromRoute($this->t('Administration'), 'system.admin'), Link::createFromRoute($this->t('Configuration'), 'system.admin_config'), Link::createFromRoute($this->t('Dmaps'), 'dmaps.settings'), Link::createFromRoute($this->t('Geocoding'), 'dmaps.locations.geocoding_options'), Link::createFromRoute($this->t('Geocoding %service', ['%service' => $geocoder]), $current_route, ['iso' => $route_match->getParameter('iso'), 'service' => $geocoder])]; $breadcrumb->setLinks($links); return $breadcrumb; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $config = \Drupal::config('uc_cart.settings'); $text = $config->get('breadcrumb_text'); $links[] = Link::createFromRoute($this->t('Home'), '<front>'); $links[] = new Link($text, Url::fromUri('internal:/' . $config->get('breadcrumb_url'), ['absolute' => TRUE])); $breadcrumb = new Breadcrumb(); $breadcrumb->setLinks($links); return $breadcrumb; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = new Breadcrumb(); $breadcrumb->addCacheContexts(['route']); $links[] = Link::createFromRoute($this->t('Home'), '<front>'); $vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($this->config->get('vocabulary')); $breadcrumb->addCacheableDependency($vocabulary); $links[] = Link::createFromRoute($vocabulary->label(), 'forum.index'); return $breadcrumb->setLinks($links); }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = new Breadcrumb(); $links[] = Link::createFromRoute(t('Home'), '<front>'); // Articles page is a view. $links[] = Link::createFromRoute(t('Articles'), 'view.articles.page_1'); $links[] = Link::createFromRoute($this->node->label(), '<none>'); $breadcrumb->setLinks($links); return $breadcrumb; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $links = array(Link::createFromRoute($this->t('Home'), '<front>')); /** @var \Drupal\rng\GroupInterface $group */ $group = $route_match->getParameter('registration_group'); if ($event = $group->getEvent()) { $links[] = new Link($event->label(), $event->urlInfo()); } $breadcrumb = new Breadcrumb(); return $breadcrumb->setLinks($links)->addCacheContexts(['route.name']); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['id'] = array('#type' => 'textfield', '#title' => $this->t('Order status ID'), '#description' => $this->t('Must be a unique ID with no spaces.'), '#size' => 32, '#maxlength' => 32, '#required' => TRUE); $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Title'), '#description' => $this->t('The order status title displayed to users.'), '#size' => 32, '#maxlength' => 48, '#required' => TRUE); $form['state'] = array('#type' => 'select', '#title' => $this->t('Order state'), '#description' => $this->t('Set which order state this status is for.'), '#options' => uc_order_state_options_list(), '#default_value' => 'post_checkout'); $form['weight'] = array('#type' => 'weight', '#title' => $this->t('List position'), '#delta' => 20, '#default_value' => 0); $form['actions'] = array('#type' => 'actions'); $form['actions']['create'] = array('#type' => 'submit', '#value' => $this->t('Create')); $form['actions']['cancel'] = array('#markup' => Link::createFromRoute($this->t('Cancel'), 'uc_order.status_add')->toString()); return $form; }
/** * {@inheritdoc} */ public function listTopics() { $topics = []; foreach ($this->moduleHandler->getImplementations('help') as $module) { $title = $this->moduleHandler->getName($module); $topics[$title] = Link::createFromRoute($title, 'help.page', ['name' => $module]); } // Sort topics by title, which is the array key above. ksort($topics); return $topics; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Skip building the form if there are no available stores. $store_query = $this->entityManager->getStorage('commerce_store')->getQuery(); if ($store_query->count()->execute() == 0) { $options = ['query' => ['destination' => Url::fromRoute('<current>')->toString()]]; $link = Link::createFromRoute('Add a new store.', 'entity.commerce_store.add_page', [], $options); $form['warning'] = ['#markup' => t("Products can't be created until a store has been added. @link", ['@link' => $link->toString()])]; return $form; } return parent::buildForm($form, $form_state); }
/** * Displays a list of an order's packaged products. * * @param \Drupal\uc_order\OrderInterface $uc_order * The order. * * @return array|\Symfony\Component\HttpFoundation\RedirectResponse * A render array, or a redirect response if there are no packaged products. */ public function listOrderPackages(OrderInterface $uc_order) { $shipping_type_options = uc_quote_shipping_type_options(); $header = array($this->t('Package ID'), $this->t('Products'), $this->t('Shipping type'), $this->t('Package type'), $this->t('Shipment ID'), $this->t('Tracking number'), $this->t('Labels'), $this->t('Actions')); $rows = array(); $result = db_query('SELECT package_id FROM {uc_packages} WHERE order_id = :id', [':id' => $uc_order->id()]); while ($package_id = $result->fetchField()) { $package = Package::load($package_id); $row = array(); // Package ID. $row[] = array('data' => array('#plain_text' => $package->package_id)); $product_list = array(); $result2 = db_query('SELECT op.order_product_id, pp.qty, op.title, op.model FROM {uc_packaged_products} pp LEFT JOIN {uc_order_products} op ON op.order_product_id = pp.order_product_id WHERE pp.package_id = :id', [':id' => $package->package_id]); foreach ($result2 as $product) { $product_list[] = $product->qty . ' x ' . $product->model; } // Products. $row[] = array('data' => array('#theme' => 'item_list', '#items' => $product_list)); // Shipping type. $row[] = isset($shipping_type_options[$package->shipping_type]) ? $shipping_type_options[$package->shipping_type] : strtr($package->shipping_type, '_', ' '); // Package type. $row[] = array('data' => array('#plain_text' => $package->pkg_type)); // Shipment ID. $row[] = isset($package->sid) ? Link::createFromRoute($package->sid, 'uc_fulfillment.view_shipment', ['uc_order' => $uc_order->id(), 'shipment_id' => $package->sid])->toString() : ''; // Tracking number. $row[] = isset($package->tracking_number) ? array('data' => array('#plain_text' => $package->tracking_number)) : ''; if ($package->label_image && ($image = file_load($package->label_image))) { $package->label_image = $image; } else { unset($package->label_image); } // Shipping label. if (isset($package->sid) && isset($package->label_image)) { $method = db_query('SELECT shipping_method FROM {uc_shipments} WHERE sid = :sid', [':sid' => $package->sid])->fetchField(); $row[] = Link::fromTextAndUrl("image goes here", Url::fromUri('base:admin/store/orders/' . $uc_order->id() . '/shipments/labels/' . $method . '/' . $package->label_image->uri, ['uc_order' => $uc_order->id(), 'method' => $method, 'image_uri' => $package->label_image->uri]))->toString(); } else { $row[] = ''; } // Operations. $ops = array('#type' => 'operations', '#links' => array('edit' => array('title' => $this->t('Edit'), 'url' => Url::fromRoute('uc_fulfillment.edit_package', ['uc_order' => $uc_order->id(), 'package_id' => $package->package_id])), 'ship' => array('title' => $this->t('Ship'), 'url' => Url::fromRoute('uc_fulfillment.new_shipment', ['uc_order' => $uc_order->id()], ['query' => ['pkgs' => $package->package_id]])), 'delete' => array('title' => $this->t('Delete'), 'url' => Url::fromRoute('uc_fulfillment.delete_package', ['uc_order' => $uc_order->id(), 'package_id' => $package->package_id])))); if ($package->sid) { $ops['#links']['cancel'] = array('title' => $this->t('Cancel'), 'url' => Url::fromRoute('uc_fulfillment.cancel_package', ['uc_order' => $uc_order->id(), 'package_id' => $package->package_id])); } $row[] = array('data' => $ops); $rows[] = $row; } if (empty($rows)) { drupal_set_message($this->t("This order's products have not been organized into packages."), 'warning'); return $this->redirect('uc_fulfillment.new_package', ['uc_order' => $uc_order->id()]); } $build['packages'] = array('#theme' => 'table', '#header' => $header, '#rows' => $rows); return $build; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = parent::build($route_match); $parents = $this->forumManager->getParents($route_match->getParameter('node')->forum_tid); if ($parents) { $parents = array_reverse($parents); foreach ($parents as $parent) { $breadcrumb[] = Link::createFromRoute($parent->label(), 'forum.page', array('taxonomy_term' => $parent->id())); } } return $breadcrumb; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#description' => $this->t('The name of the attribute used in administrative forms'), '#default_value' => '', '#required' => TRUE); $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#description' => $this->t("Enter a label that customers will see instead of the attribute name. Use <none> if you don't want a title to appear at all."), '#default_value' => ''); $form['description'] = array('#type' => 'textfield', '#title' => $this->t('Help text'), '#description' => $this->t('<b>Optional.</b> Enter the help text that will display beneath the attribute on product add to cart forms.'), '#default_value' => '', '#maxlength' => 255); $form['required'] = array('#type' => 'checkbox', '#title' => $this->t('Make this attribute required, forcing the customer to choose an option.'), '#description' => $this->t('Selecting this for an attribute will disregard any default option you specify.<br />May be overridden at the product level.'), '#default_value' => 0); $form['display'] = array('#type' => 'select', '#title' => $this->t('Display type'), '#description' => $this->t('This specifies how the options for this attribute will be presented.<br />May be overridden at the product level.'), '#options' => _uc_attribute_display_types(), '#default_value' => 1); $form['ordering'] = array('#type' => 'weight', '#delta' => 25, '#title' => $this->t('List position'), '#description' => $this->t('Multiple attributes on an add to cart form are sorted by this value and then by their name.<br />May be overridden at the product level.'), '#default_value' => 0); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Submit'), '#suffix' => Link::createFromRoute($this->t('Cancel'), 'uc_attribute.overview')->toString()); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $aid = NULL) { $form['aid'] = array('#type' => 'value', '#value' => $aid); $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#description' => $this->t('This name will appear to customers on product add to cart forms.'), '#default_value' => '', '#required' => TRUE, '#weight' => 0); $form['ordering'] = array('#type' => 'weight', '#delta' => 50, '#title' => $this->t('List position'), '#description' => $this->t('Options will be listed sorted by this value and then by their name.<br />May be overridden at the product level.'), '#default_value' => 0, '#weight' => 4); $form['adjustments'] = array('#type' => 'fieldset', '#title' => $this->t('Default adjustments'), '#description' => $this->t('Enter a positive or negative value for each adjustment applied when this option is selected.<br />Any of these may be overriden at the product level.'), '#weight' => 8); $form['adjustments']['cost'] = array('#type' => 'uc_price', '#title' => $this->t('Cost'), '#default_value' => 0, '#weight' => 1, '#allow_negative' => TRUE); $form['adjustments']['price'] = array('#type' => 'uc_price', '#title' => $this->t('Price'), '#default_value' => 0, '#weight' => 2, '#allow_negative' => TRUE); $form['adjustments']['weight'] = array('#type' => 'textfield', '#title' => $this->t('Weight'), '#default_value' => 0, '#weight' => 3); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Submit'), '#suffix' => Link::createFromRoute($this->t('Cancel'), 'uc_attribute.options', ['aid' => $aid])->toString(), '#weight' => 10); return $form; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $links = array(Link::createFromRoute($this->t('Home'), '<front>')); $registration = $route_match->getParameter('registration'); if ($event = $registration->getEvent()) { $links[] = new Link($event->label(), $event->urlInfo()); } if ('entity.registration.canonical' != $route_match->getRouteName()) { $links[] = new Link($registration->label(), $registration->urlInfo()); } $breadcrumb = new Breadcrumb(); return $breadcrumb->setLinks($links)->addCacheContexts(['route.name']); }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = [Link::createFromRoute($this->t('Home'), '<front>')]; $entity = $route_match->getParameter('entity'); $breadcrumb[] = new Link($entity->label(), $entity->urlInfo()); if (($pid = $route_match->getParameter('pid')) && ($comment = $this->storage->load($pid))) { /** @var \Drupal\comment\CommentInterface $comment */ // Display link to parent comment. // @todo Clean-up permalink in https://www.drupal.org/node/2198041 $breadcrumb[] = new Link($comment->getSubject(), $comment->urlInfo()); } return $breadcrumb; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $links = array(Link::createFromRoute($this->t('Home'), '<front>')); /** @var \Drupal\rng\RuleComponentInterface $component */ $component = $route_match->getParameter('rng_rule_component'); if ($rule = $component->getRule()) { if ($event = $rule->getEvent()) { $links[] = new Link($event->label(), $event->urlInfo()); } } $breadcrumb = new Breadcrumb(); return $breadcrumb->setLinks($links)->addCacheContexts(['route.name']); }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $term = $route_match->getParameter('taxonomy_term'); // @todo This overrides any other possible breadcrumb and is a pure // hard-coded presumption. Make this behavior configurable per // vocabulary or term. $breadcrumb = array(); while ($parents = taxonomy_term_load_parents($term->id())) { $term = array_shift($parents); $breadcrumb[] = Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id())); } $breadcrumb[] = Link::createFromRoute($this->t('Home'), '<front>'); $breadcrumb = array_reverse($breadcrumb); return $breadcrumb; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = parent::build($route_match); // Add all parent forums to breadcrumbs. $term_id = $route_match->getParameter('taxonomy_term')->id(); $parents = $this->forumManager->getParents($term_id); if ($parents) { foreach (array_reverse($parents) as $parent) { if ($parent->id() != $term_id) { $breadcrumb[] = Link::createFromRoute($parent->label(), 'forum.page', array('taxonomy_term' => $parent->id())); } } } return $breadcrumb; }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = new Breadcrumb(); $breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>')); $breadcrumb->addCacheContexts(['route']); /** @var JobItemInterface $job_item */ $job_item = $route_match->getParameter('tmgmt_job_item'); $breadcrumb->addCacheableDependency($job_item); // Add links to administration, translation, job overview and job to the // breadcrumb. $breadcrumb->addLink(Link::createFromRoute($this->t('Administration'), 'system.admin')); $breadcrumb->addLink(Link::createFromRoute($this->t('Translation'), 'tmgmt.admin_tmgmt')); $breadcrumb->addLink(Link::createFromRoute($this->t('Job overview'), 'view.tmgmt_job_overview.page_1')); $breadcrumb->addLink(Link::createFromRoute($job_item->getJob()->label(), 'entity.tmgmt_job.canonical', array('tmgmt_job' => $job_item->getJobId()))); return $breadcrumb; }
/** * @dataProvider providerTestThemeRenderAndAutoescape */ public function testThemeRenderAndAutoescape($arg, $expected) { if (is_array($arg) && isset($arg['#type']) && $arg['#type'] === 'link') { $arg = Link::createFromRoute($arg['#title'], $arg['#url']); } $context = new RenderContext(); // Use a closure here since we need to render with a render context. $theme_render_and_autoescape = function () use($arg) { return theme_render_and_autoescape($arg); }; /** @var \Drupal\Core\Render\RendererInterface $renderer */ $renderer = \Drupal::service('renderer'); $output = $renderer->executeInRenderContext($context, $theme_render_and_autoescape); $this->assertEquals($expected, $output); $this->assertInternalType('string', $output); }
/** * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { $breadcrumb = new Breadcrumb(); $node = $route_match->getParameter('node'); // Homepage link. $links[] = Link::createFromRoute($this->t('Home'), '<front>'); // First assigned tag. if (!empty($node->field_tags[0]->target_id)) { $tid = $node->field_tags[0]->target_id; $term_name = Term::load($tid)->get('name')->value; $links[] = Link::createFromRoute($term_name, 'entity.taxonomy_term.canonical', ['taxonomy_term' => $tid]); } // The node itself. $links[] = Link::fromTextAndUrl($node->getTitle(), Url::fromRoute('<current>')); $breadcrumb->addCacheContexts(['route']); return $breadcrumb->setLinks($links); }