Inherit Template

Есть плагин Inherit Template
Его код.
В TV выбирается шаблон. Когда создаётся дочерний ресурс, то у него устанавливается выбранный в TV у родителя шаблон. Как сделать, чтобы у нового (дочернего) в TV устанавливался шаблон родителя? А может даже пустой, если в параметр плагина установить.
Также при быстром создании не работает плагин. Если с этим, что-то можно сделать дополнительно, то это будет хорошо.
Кто хорошо разбирается можете подправить? Спасибо.
<?php
/**
 * Inherit Template for MODx Revolution
 *
 * This plugin sets the new document template to have a default template from
 * parent's TV selection. This is only triggered by 'OnDocFormRender' event.
 * This only works one level, as it's intended.
 *
 * Inherit Template is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * Inherit Template is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * Inherit Template; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * @author      goldsky     <goldsky.milis@gmail.com>
 * @copyright   Copyright © 2012, goldsky
 * @license     GPL v2
 *
 * @package     Inherit Template
 * @subpackage  plugin
 */
// this plugin only apply to the new document
if (empty($scriptProperties['mode']) || $scriptProperties['mode'] !== 'new') {
    return;
}
if ($modx->event->name === 'OnDocFormRender') {
    // get the parent's ID
    $parentObj = $modx->getObject('modResource', $_REQUEST['parent']);
    if (!$parentObj) {
        return;
    }
    $parent = $parentObj->toArray();

    // checking the parent's TV
    $inheritTplObj = $modx->getObject('modTemplateVar', array(
        'name' => $modx->getOption('inheritTpl.tvname')
            ));

    if (!$inheritTplObj || !$inheritTplObj->hasTemplate($parent['template'])) {
        return;
    }

    // get the value from the parent's TV
    $inheritTpl = $inheritTplObj->toArray();
    $tvValueObj = $modx->getObject('modTemplateVarResource', array(
        'tmplvarid' => $inheritTpl['id'],
        'contentid' => $parent['id']
            ));
    if (!$tvValueObj) {
        return;
    }
    $tvValueArray = $tvValueObj->toArray();

    // force/override the template to the opening document
    $modx->controller->setProperty('template', $tvValueArray['value']);

    return;
}
return;
Дмитрий
08 февраля 2018, 18:06
modx.pro
1 537
0

Комментарии: 1

Максим
09 февраля 2018, 17:24
+1
Да конечно можно! Логика такая:

Разбираемся с окном быстрого создания.
1) Очевидно что при вызове быстрого создания не происходит событие OnDocFormRender. Нужно отыскать событие которое происходит при открытии окна быстрого создания и добавить его

Разбираемся с новыми.
1) Находим нужное событие
2) Пишем плагин на это событие.

Все примеры у вас есть в вашем коде!
    Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
    1