Убрать часть Url (вопрос по готовому плагину)

В этой теме — modx.pro/help/5094/ пользователь Андрей написал плагин исключения контейнера для сортировки ресурсов из Url Вот этот плагин:

<?php
if ($modx->event->name == 'OnDocFormSave') {

	$parentIds = $modx->getParentIds($id, 4, array('context' => 'web'));   // Получаем id всех родителей ресурса
	$res = $modx->getObject('modResource',$id);
	$curAlias = $res->get('alias');   // Алиас текущего ресурса

	$cnt = count($parentIds);  // Количество родителей

	if($cnt > 2) { 

		$aliases = array();   // Массив для всех найденных алиасов

		foreach($parentIds as $v) {
			if($v == 22 || $v == 0) continue;  // Если родитель - контейнер Shop(22) или главный родитель (0) - пропускаем.

			$obj = $modx->getObject('modResource', $v);
			$alias = $obj->get('alias');
			$aliases[] = $alias;
		}

		$resource->set('uri', implode('/',array_reverse($aliases)) . '/' . $curAlias);

	} else {
		$resource->set('uri', $curAlias);
	}

	$resource->set('uri_override', true);
        $resource->save();

}


Подскажите пожалуйста, где в этом коде можно прописать определенный контейнер ресурса для исключения? В решении автора, исключается родитель у всех ресурсов, а мне надо определенный (15). Сам уже много перепробовал, но ничего не получается.
Спасибо!
Сергей Сергеевич
10 февраля 2016, 17:27
modx.pro
1 815
0

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

Воеводский Михаил
11 февраля 2016, 23:26
0
if($v == 22 || $v == 0) continue;

В этой строке задаются родители, исключаемые из url.
Это слишком очевидно, потому поясни вопрос, что непонятно в этом коде.
    Сергей Сергеевич
    15 февраля 2016, 20:19
    0
    Да, это очевидно, и я пробовал это сделать. Суть проблемы такая — есть у меня ресурс-контейнер, под id 15, и мне нужно убрать его в урлах в его дочерних документах. А этот плагин, убирает родителя у всех ресурсах, кто имеет родителя. Вот я и спрашиваю. что здесь поменять, чтобы редактировался только один родитель а не все в контексте.
      Воеводский Михаил
      15 февраля 2016, 20:29
      1
      0
      <?php
      if ($modx->event->name == 'OnDocFormSave') {
      
          $excludedParent = 15;
          $parentIds = $modx->getParentIds($id, 4, array('context' => 'web'));   // Получаем id всех родителей ресурса
          if (in_array($excludedParent, $parentIds)) return;
          $curAlias = $resource->get('alias');   // Алиас текущего ресурса
      
          if(count($parentIds) > 2) {
              $aliases = array();   // Массив для всех найденных алиасов
              foreach($parentIds as $v) {
                  if($v != $excludedParent) {
                      $obj = $modx->getObject('modResource', $v);
                      $alias = $obj->get('alias');
                      $aliases[] = $alias;
                  }
              }
              $resource->set('uri', implode('/',array_reverse($aliases)) . '/' . $curAlias);
              $resource->set('uri_override', true);
              $resource->save();
          }
      }
        Сергей Сергеевич
        18 февраля 2016, 14:47
        0
        Здравствуйте! Спасибо за помощь, но при сохранении документа, не происходит заморозка URI, т.е родитель у ресурса не исключается. И еще зависает ресурс — подождите идет сохранение… Отключаешь плагин, перестает зависать.
          Павел Гвоздь
          18 февраля 2016, 15:00
          0
          зависает ресурс — подождите идет сохранение… Отключаешь плагин, перестает зависать
          А лог ошибок MODX можно глянуть, когда это происходит?
            Сергей Сергеевич
            18 февраля 2016, 16:37
            0
            [2016-02-18 14:08:35] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:08:36] (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()
            [2016-02-18 14:08:37] (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()
            [2016-02-18 14:16:35] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:16:51] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:17:42] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:18:05] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:19:52] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:20:19] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:22:52] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:24:51] (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()
            [2016-02-18 14:24:51] (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()
            [2016-02-18 14:24:56] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:40:20] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:40:23] (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()
            [2016-02-18 14:40:23] (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()
            [2016-02-18 14:40:37] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:43:49] (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()
            [2016-02-18 14:43:49] (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()
            [2016-02-18 14:44:04] (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()
            [2016-02-18 14:44:04] (ERROR @ /index.php) `[[+id]]` is not a valid integer and may not be passed to makeUrl()
            [2016-02-18 14:45:00] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:45:08] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:45:38] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:45:57] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:20] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:28] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:29] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:30] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:31] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:31] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:31] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:31] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:31] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:31] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
            [2016-02-18 14:46:31] (ERROR @ /connectors/index.php) xPDOObject::isDirty() — Attempt to check if an unknown field (exclude_alias_in_childs) has been modified.
          Воеводский Михаил
          19 февраля 2016, 02:24
          0
          Код писал прямо здесь, не проверял.
          Отправьте доступ в админку на почту, завтра вечером гляну.
            Сергей Сергеевич
            22 февраля 2016, 13:09
            0
            Здравствуйте! К сожалению к рабочему сайту не могу дать доступ, т.к это не мой сайт. Я создам тестовый сайт и кину вам доступ
    Андрей Шевяков
    26 января 2017, 11:02
    0
    Нашел решение для исключения ресурсов-контейнеров из урл у Ильи Уткина.
    Попробовал у себя на сайте, все отлично работает.
    Вот статья: Исключение алиаса ресурса в URL дочерних ресурсов
    Может кому пригодится!
      Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
      12