php - Pimcore: How to override built-in controller -


i attempting extend bulk object import functionality in pimcore restrict users fields have available them in custom layout.

the file need override

pimcore/modules/admin/controllers/objectcontroller.php

and believe method need extend is:

public function importgetfileinfoaction() {     $success = true;     $supportedfieldtypes = ["checkbox", "country", "date", "datetime", "href", "image", "input", "language", "table", "multiselect", "numeric", "password", "select", "slider", "textarea", "wysiwyg", "objects", "multihref", "geopoint", "geopolygon", "geobounds", "link", "user", "email", "gender", "firstname", "lastname", "newsletteractive", "newsletterconfirmed", "countrymultiselect", "objectsmetadata"];     $file = pimcore_system_temp_directory . "/import_" . $this->getparam("id");     // determine type     $dialect = tool\admin::determinecsvdialect(pimcore_system_temp_directory . "/import_" . $this->getparam("id") . "_original");     $count = 0;     if (($handle = fopen($file, "r")) !== false) {         while (($rowdata = fgetcsv($handle, 0, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar)) !== false) {             if ($count == 0) {                 $firstrowdata = $rowdata;             }             $tmpdata = [];             foreach ($rowdata $key => $value) {                 $tmpdata["field_" . $key] = $value;             }             $data[] = $tmpdata;             $cols = count($rowdata);             $count++;             if ($count > 18) {                 break;             }         }         fclose($handle);     }     // class data     $class = object\classdefinition::getbyid($this->getparam("classid"));     $fields = $class->getfielddefinitions();     $availablefields = [];     foreach ($fields $key => $field) {         $config = null;         $title = $field->getname();         if (method_exists($field, "gettitle")) {             if ($field->gettitle()) {                 $title = $field->gettitle();             }         }         if (in_array($field->getfieldtype(), $supportedfieldtypes)) {             $availablefields[] = [$field->getname(), $title . "(" . $field->getfieldtype() . ")"];         }     }     $mappingstore = [];     ($i = 0; $i < $cols; $i++) {         $mappedfield = null;         if ($availablefields[$i]) {             $mappedfield = $availablefields[$i][0];         }         $firstrow = $i;         if (is_array($firstrowdata)) {             $firstrow = $firstrowdata[$i];             if (strlen($firstrow) > 40) {                 $firstrow = substr($firstrow, 0, 40) . "...";             }         }         $mappingstore[] = [             "source" => $i,             "firstrow" => $firstrow,             "target" => $mappedfield         ];     }     //how many rows     $csv = new splfileobject($file);     $csv->setflags(splfileobject::read_csv);     $csv->setcsvcontrol($dialect->delimiter, $dialect->quotechar, $dialect->escapechar);     $rows = 0;     $nbfields = 0;     foreach ($csv $fields) {         if (0 === $rows) {             $nbfields = count($fields);             $rows++;         } elseif ($nbfields == count($fields)) {             $rows++;         }     }     $this->_helper->json([         "success" => $success,         "datapreview" => $data,         "datafields" => array_keys($data[0]),         "targetfields" => $availablefields,         "mappingstore" => $mappingstore,         "rows" => $rows,         "cols" => $cols     ]); } 

specifically these 2 lines:

$class = object\classdefinition::getbyid($this->getparam("classid"));

$fields = $class->getfielddefinitions();

what i'd figure out how fields user can see in custom layout, filter out $fields accordingly. i'd avoid overwriting core file, , instead love extend plugin.

you have create plugin overrides menu items in ui, in order substitute standard object import custom one.

you need create customobjectcontroller can extend standard objectcontroller.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -