Answer the question
In order to leave comments, you need to log in
Can you suggest how to make menu.sections and UF_* friends?
It is necessary to make friends to display custom fields in menu items.
I understand that you need to customize the code of the menu.sections
component in the api requests component. OK . I added to make a request for all UF_*. in two places. What's next?)
if(!isset($arParams["CACHE_TIME"]))
$arParams["CACHE_TIME"] = 36000000;
$arParams["ID"] = intval($arParams["ID"]);
$arParams["IBLOCK_ID"] = intval($arParams["IBLOCK_ID"]);
$arParams["DEPTH_LEVEL"] = intval($arParams["DEPTH_LEVEL"]);
if($arParams["DEPTH_LEVEL"]<=0)
$arParams["DEPTH_LEVEL"]=1;
$arResult["SECTIONS"] = array();
$arResult["ELEMENT_LINKS"] = array();
if($this->StartResultCache())
{
if(!CModule::IncludeModule("iblock"))
{
$this->AbortResultCache();
}
else
{
$arFilter = array(
"IBLOCK_ID"=>$arParams["IBLOCK_ID"],
"GLOBAL_ACTIVE"=>"Y",
"IBLOCK_ACTIVE"=>"Y",
"<="."DEPTH_LEVEL" => $arParams["DEPTH_LEVEL"],
);
$arOrder = array(
"left_margin"=>"asc",
);
$rsSections = CIBlockSection::GetList($arOrder, $arFilter, false, array(
"ID",
"DEPTH_LEVEL",
"NAME",
"SECTION_PAGE_URL",
'UF_*',
));
if($arParams["IS_SEF"] !== "Y")
$rsSections->SetUrlTemplates("", $arParams["SECTION_URL"]);
else
$rsSections->SetUrlTemplates("", $arParams["SEF_BASE_URL"].$arParams["SECTION_PAGE_URL"]);
while($arSection = $rsSections->GetNext())
{
$arResult["SECTIONS"][] = array(
"ID" => $arSection["ID"],
"DEPTH_LEVEL" => $arSection["DEPTH_LEVEL"],
"~NAME" => $arSection["~NAME"],
"~SECTION_PAGE_URL" => $arSection["~SECTION_PAGE_URL"],
);
$arResult["ELEMENT_LINKS"][$arSection["ID"]] = array();
}
$this->EndResultCache();
}
}
//In "SEF" mode we'll try to parse URL and get ELEMENT_ID from it
if($arParams["IS_SEF"] === "Y")
{
$engine = new CComponentEngine($this);
if (CModule::IncludeModule('iblock'))
{
$engine->addGreedyPart("#SECTION_CODE_PATH#");
$engine->setResolveCallback(array("CIBlockFindTools", "resolveComponentEngine"));
}
$componentPage = $engine->guessComponentPath(
$arParams["SEF_BASE_URL"],
array(
"section" => $arParams["SECTION_PAGE_URL"],
"detail" => $arParams["DETAIL_PAGE_URL"],
),
$arVariables
);
if($componentPage === "detail")
{
CComponentEngine::InitComponentVariables(
$componentPage,
array("SECTION_ID", "ELEMENT_ID"),
array(
"section" => array("SECTION_ID" => "SECTION_ID"),
"detail" => array("SECTION_ID" => "SECTION_ID", "ELEMENT_ID" => "ELEMENT_ID"),
),
$arVariables
);
$arParams["ID"] = intval($arVariables["ELEMENT_ID"]);
}
}
if(($arParams["ID"] > 0) && (intval($arVariables["SECTION_ID"]) <= 0) && CModule::IncludeModule("iblock"))
{
$arSelect = array("ID", "IBLOCK_ID", "DETAIL_PAGE_URL", "IBLOCK_SECTION_ID", "UF_*");
$arFilter = array(
"ID" => $arParams["ID"],
"ACTIVE" => "Y",
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
);
$rsElements = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect);
if(($arParams["IS_SEF"] === "Y") && ($arParams["DETAIL_PAGE_URL"] <> ''))
$rsElements->SetUrlTemplates($arParams["SEF_BASE_URL"].$arParams["DETAIL_PAGE_URL"]);
while($arElement = $rsElements->GetNext())
{
$arResult["ELEMENT_LINKS"][$arElement["IBLOCK_SECTION_ID"]][] = $arElement["~DETAIL_PAGE_URL"];
}
}
$aMenuLinksNew = array();
$menuIndex = 0;
$previousDepthLevel = 1;
foreach($arResult["SECTIONS"] as $arSection)
{
if ($menuIndex > 0)
$aMenuLinksNew[$menuIndex - 1][3]["IS_PARENT"] = $arSection["DEPTH_LEVEL"] > $previousDepthLevel;
$previousDepthLevel = $arSection["DEPTH_LEVEL"];
$arResult["ELEMENT_LINKS"][$arSection["ID"]][] = urldecode($arSection["~SECTION_PAGE_URL"]);
$aMenuLinksNew[$menuIndex++] = array(
htmlspecialcharsbx($arSection["~NAME"]),
$arSection["~SECTION_PAGE_URL"],
$arResult["ELEMENT_LINKS"][$arSection["ID"]],
array(
"FROM_IBLOCK" => true,
"IS_PARENT" => false,
"DEPTH_LEVEL" => $arSection["DEPTH_LEVEL"],
),
);
}
return $aMenuLinksNew;
?>
Answer the question
In order to leave comments, you need to log in
Well, what's next, you need to add these UFs to the $aMenuLinksNew array, it is filled in a loop through $arResult["SECTIONS"], i.e. in order not to change something much, above after the request, in the while loop, $arResult["SECTIONS"] is filled in and add your UFs there.
Then where $aMenuLinksNew is filled, the last array
array(
"FROM_IBLOCK" => true,
"IS_PARENT" => false,
"DEPTH_LEVEL" => $arSection["DEPTH_LEVEL"],
),
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question