A
A
Akorolev2020-01-28 19:22:58
1C-Bitrix
Akorolev, 2020-01-28 19:22:58

How to embed \Bitrix\Main\UI\FileInput into iblock.element.add.form?

How to embed \Bitrix\Main\UI\FileInputin iblock.element.add.forminstead of <input type="file" />?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-01-29
@Akorolev

Hello.
Previously, it was not possible to do this, I had to open the kernel ...
Apparently, without a custom component, it will not work. When loading through the standard type=file field, the data about the file gets into the $_FILES array where there is tmp_name - the full path to the temporary file, and when using \Bitrix\Main\UI\FileInput in $_REQUEST where there is also tmp_name but with a truncated value
5e316661c6ca9430784855.jpeg
should be
5e316675706e8091370218.jpeg
In the component CIBlockElement::Add is called next -

CIBlockElement::Add --> CFile::CheckImageFile --> CFile::GetImageSize($arFile["tmp_name"], true, $flashEnabled)

here in the last function, a jamb occurs if tmp_name is not full (the full path can be obtained using CIBlock::makeFileArray)
An example of component customization (tested only for PREVIEW_PICTURE):
1. In the component.php file, find the check
if($arResult["PROPERTY_LIST_FULL"][$propertyID]["PROPERTY_TYPE"] == "F")

замени
$arFile = $_FILES["PROPERTY_FILE_".$propertyID."_0"];
на
$arFile = ($_FILES["PROPERTY_FILE_".$propertyID."_0"] ? $_FILES["PROPERTY_FILE_".$propertyID."_0"] : CIBlock::makeFileArray($_REQUEST["PROPERTY_FILE_".$propertyID."_0"]));

2. In template.php replace all case "F":
for ($i = 0; $i<$inputNum; $i++)
{
  $name = 'PROPERTY_FILE_'.$propertyID.'_'.($arResult["ELEMENT_PROPERTIES"][$propertyID][$i]["VALUE_ID"] ? $arResult["ELEMENT_PROPERTIES"][$propertyID][$i]["VALUE_ID"] : $i);
  $value = intval($propertyID) > 0 ? $arResult["ELEMENT_PROPERTIES"][$propertyID][$i]["VALUE"] : $arResult["ELEMENT"][$propertyID];

  echo \Bitrix\Main\UI\FileInput::createInstance(array(
    "name" => $name,
    "description" => true,
    "upload" => true,
    "allowUpload" => "I",
    "medialib" => true,
    "fileDialog" => true,
    "cloud" => true,
    "delete" => true,
    "maxCount" => 1
  ))->show(
    $value,
    $value ? true : false
  );
}

PS take into account the fact that it was tested only for PREVIEW_PICTURE for properties, for multiple it is necessary to add exactly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question