定制 origindesign/custom_alias 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

origindesign/custom_alias

最新稳定版本:v5.0

Composer 安装命令:

composer require origindesign/custom_alias

包简介

Custom Alias - A Drupal 8 module for overriding URL alias

README 文档

README

<?php


use Drupal\node\NodeInterface;




/**
 * Setup key => value pairs to match field value to path alias
 */
function getOptions(){

    $options = array(

        'service' => array(
            'Accommodation' => '/services/accommodation/',
            'Business' => '/business-listing/business/',
            'Dining & Nightlife' => '/things-to-do/dining-nightlife/'
        )

    );

    return $options;

}


/**
 * Set path alias on insert
 * @param NodeInterface $node
 */
function custom_alias_node_insert(NodeInterface $node) {

    // Set options array
    $options = getOptions();

    // Setup per content type
    switch($node->getType()){

        case 'service':

            // Get service taxonomy
            $field = $node->get('field_category')->view()[0]['#title'];

            // Set options
            $settings = $options['service'];

            break;

    }

    // Save path alias
    $process = \Drupal::service('custom_alias.alias_manager')->processPath($node, $field, $settings, 'save');

}


/**
 * Set path alias on update
 * @param NodeInterface $node
 */
function custom_alias_node_update(NodeInterface $node) {

    // Set options array
    $options = getOptions();

    // Setup per content type
    switch($node->getType()){

        case 'service':

            // Get service taxonomy
            $field = $node->get('field_category')->view()[0]['#title'];

            // Set options
            $settings = $options['service'];

            break;

    }

    // Save path alias
    $process = \Drupal::service('custom_alias.alias_manager')->processPath($node, $field, $settings, 'update');

}


/**
 * Disable Url Alias field
 * @param $form
 * @param \Drupal\Core\Form\FormStateInterface $form_state
 * @param $form_id
 */
function custom_alias_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

    switch ($form_id) {
        case 'node_service_form':
        case 'node_service_edit_form':
            $form['path']['#disabled'] = 'disabled';
            break;
    }

}

统计信息

  • 总下载量: 3.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-22