X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fpathauto%2Fsrc%2FPathautoWidget.php;fp=web%2Fmodules%2Fcontrib%2Fpathauto%2Fsrc%2FPathautoWidget.php;h=3ca0490089b507b0108a3915ad7cee7e7d0f3f67;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/pathauto/src/PathautoWidget.php b/web/modules/contrib/pathauto/src/PathautoWidget.php new file mode 100644 index 000000000..3ca049008 --- /dev/null +++ b/web/modules/contrib/pathauto/src/PathautoWidget.php @@ -0,0 +1,71 @@ +getEntity(); + + // Taxonomy terms do not have an actual fieldset for path settings. + // Merge in the defaults. + // @todo Impossible to do this in widget, use another solution + /* + $form['path'] += array( + '#type' => 'fieldset', + '#title' => $this->t('URL path settings'), + '#collapsible' => TRUE, + '#collapsed' => empty($form['path']['alias']), + '#group' => 'additional_settings', + '#attributes' => array( + 'class' => array('path-form'), + ), + '#access' => \Drupal::currentUser()->hasPermission('create url aliases') || \Drupal::currentUser()->hasPermission('administer url aliases'), + '#weight' => 30, + '#tree' => TRUE, + '#element_validate' => array('path_form_element_validate'), + );*/ + + $pattern = \Drupal::service('pathauto.generator')->getPatternByEntity($entity); + if (empty($pattern)) { + return $element; + } + + if (\Drupal::currentUser()->hasPermission('administer pathauto')) { + $description = $this->t('Uncheck this to create a custom alias below. Configure URL alias patterns.', ['@admin_link' => Url::fromRoute('entity.pathauto_pattern.collection')->toString()]); + } + else { + $description = $this->t('Uncheck this to create a custom alias below.'); + } + + $element['pathauto'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Generate automatic URL alias'), + '#default_value' => $entity->path->pathauto, + '#description' => $description, + '#weight' => -1, + ); + + // Add JavaScript that will disable the path textfield when the automatic + // alias checkbox is checked. + $element['alias']['#states']['disabled']['input[name="path[' . $delta . '][pathauto]"]'] = array('checked' => TRUE); + + // Override path.module's vertical tabs summary. + $element['alias']['#attached']['library'] = ['pathauto/widget']; + + return $element; + } + +}