예제 #1
0
 /**
  * Adds a print route for each content entity.
  *
  * @param \Drupal\Core\Routing\RouteBuildEvent $event
  *   The route build event.
  */
 public function routes(RouteBuildEvent $event)
 {
     $collection = $event->getRouteCollection();
     foreach ($this->printableEntityManager->getPrintableEntities() as $entity_type => $entity_definition) {
         $route = new Route("/printable/{printable_format}/{$entity_type}/{entity}", array('_controller' => 'Drupal\\printable\\Controller\\PrintableController::showFormat', '_title' => 'Printable'), array('_permission' => 'view printer friendly versions'), array('parameters' => array('entity' => array('type' => 'entity:' . $entity_type))));
         $collection->add('printable.show_format.' . $entity_type, $route);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $printable_format = NULL)
 {
     // Allow users to choose what entities printable is enabled for.
     $form['settings']['printable_entities'] = array('#type' => 'checkboxes', '#title' => $this->t('Printable Enabled Entities'), '#description' => $this->t('Select the entities that printable support should be enabled for.'), '#options' => array(), '#default_value' => array());
     // Build the options array.
     foreach ($this->printableEntityManager->getCompatibleEntities() as $entity_type => $entity_definition) {
         $form['settings']['printable_entities']['#options'][$entity_type] = $entity_definition->getLabel();
     }
     // Build the default values array.
     foreach ($this->printableEntityManager->getPrintableEntities() as $entity_type => $entity_definition) {
         $form['settings']['printable_entities']['#default_value'][] = $entity_type;
     }
     // Provide option to open printable page in a new tab/window.
     $form['settings']['open_target_blank'] = array('#type' => 'checkbox', '#title' => $this->t('Open in New Tab'), '#description' => $this->t('Open the printable version in a new tab/window.'), '#default_value' => $this->config('printable.settings')->get('open_target_blank'));
     // Allow users to include CSS from the current theme.
     $form['settings']['css_include'] = array('#type' => 'textfield', '#title' => $this->t('CSS Include'), '#description' => $this->t('Specify an additional CSS file to include. Relative to the root of the Drupal install. The token <em>[theme:theme_machine_name]</em> is available.'), '#default_value' => $this->config('printable.settings')->get('css_include'));
     // Provide option to turn off link extraction.
     $form['settings']['extract_links'] = array('#type' => 'checkbox', '#title' => $this->t('Extract Links'), '#description' => $this->t('Extract any links in the content, e.g. "Some Link (http://drupal.org)'), '#default_value' => $this->config('printable.settings')->get('extract_links'));
     return parent::buildForm($form, $form_state);
 }