M
M
Mechanic2020-08-16 18:38:04
1C-Bitrix
Mechanic, 2020-08-16 18:38:04

How to overwrite the NC rule for a custom Bitrix component while saving the settings?

Good afternoon friends! Please share your experience in solving the problem.

Have our own integrated CNC component.
It handles addresses like:

  • /somedir/element_code/
  • /somedir/element_code/subdir1/
  • /somedir/element_code/subdir2/
  • /somedir/element_code/subdir3/


Problem:
When editing and saving the component settings (even if you do not affect the parameters relative to the CNC), the address processing rule is overwritten and the CNC stops working - you have to go and manually edit the processing rule to the previous working values. Bitrix TP cannot help.

Component settings:
  • CNC directory (relative to site root): /somedir/
  • Detail page link template: #CODE#/
  • Detail page link template (subsection #1): #CODE#/subdir1/
  • Detail page link template (subsection #2): #CODE#/subdir2/
  • Detail page link template (subsection #3): #CODE#/subdir3/


Address processing rule BEFORE component settings are saved::
  • Condition: #^/somedir/([^/]+)/([^/]+)?/?(.*)$#
  • Component: custom:mycatalog
  • File: /somedir/index.php
  • Rule: element_code=$1&subdir=$2


Address processing rule AFTER SAVING component settings:
  • Condition: #^/somedir/#
  • Component: custom:mycatalog
  • File: /somedir/index.php
  • Rule: _blank_


About this in the documentation: (more on this topic nothing was found)
5f3950ec35ed9129466173.png

Do you know any ways to solve this problem? I will be glad to any tip! Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-08-17
@bitrixweb

You have a complex component, it correctly rewrites urlrewrite. When you turn on SEF_MODE you have an extra. the SEF_URL_TEMPLATES parameter, here it will be your rules, which you want to write like this #^/somedir/([^/]+)/([^/]+)?/?(.*)$#
Save your component through a visual editor, then manually (for now) replace in the index file

"SEF_URL_TEMPLATES" => array(
  "element" => "#CODE#/",
  "articles" => "#CODE#/articles/",
  "articles2" => "#CODE#/articles2/",
  "articles3" => "#CODE#/articles3/",
),

Now, upon request /somedir/#CODE#/articles/ , you will connect the articles.php page (the rest, respectively - /somedir/#CODE#/articles2/ will be articles2.php ), which you need to create in the complex component template. in $arResult['VARIABLES']['CODE'] you will have the code of your element, you can get the necessary links - here, as you think is right, at least make queries here, at least take it to the level of a complex component, I would write for such links another simple component.
Well, it remains to be done so that your SEF_URL_TEMPLATES can be edited through a visual editor, in any complex component in the .parameters.php file you can see (landmark, everything related to SEF_MODE)
An example based on the news component:
5f3a8ffb3d32e894639962.jpeg
standard Bitrix eshop, news section, news component, everything works as it should
Edits in the .parameters.php file of the component, SEF_MODE section
// ...............
"SEF_MODE" => Array(
  "element" => array(
    "NAME" => GetMessage("T_IBLOCK_SEF_PAGE_NEWS_DETAIL"),
    "DEFAULT" => "#CODE#/",
    "VARIABLES" => array("CODE"),
  ),
  "articles" => array(
    "NAME" => "Страница связанных articles",
    "DEFAULT" => "search/",
    "VARIABLES" => array(),
  ),

  "articles2" => array(
    "NAME" => "Страница связанных articles2",
    "DEFAULT" => "search/",
    "VARIABLES" => array(),
  ),

  "articles3" => array(
    "NAME" => "Страница связанных articles3",
    "DEFAULT" => "search/",
    "VARIABLES" => array(),
  ),

),
// ................

в конце по вкусу можно добавить, что-то типа
if($arCurrentValues["SEF_MODE"]=="Y")
{
  $arComponentParameters["PARAMETERS"]["VARIABLE_ALIASES"] = array();
  $arComponentParameters["PARAMETERS"]["VARIABLE_ALIASES"]["CODE"] = array(
    "NAME" => GetMessage("CP_BC_VARIABLE_ALIASES_ELEMENT_ID"),
    "TEMPLATE" => "#CODE#",
  );
}

In the component.php file, you can add
$arDefaultUrlTemplates404 = array(
  "news" => "",
  "element" => "#CODE#/",
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question