Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Fatal error: [] operator not supported for strings in … #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<extension id="uploadselectboxfield" status="released" xmlns="http://symphony-cms.com/schemas/extension/1.0">
<name>Uploaded Files Select Box</name>
<description>Displays a select box list of files from a chosen folder</description>
<repo type="github">https://github.com/symphonists/uploadselectboxfield</repo>
<repo type="github">https://github.com/animaux/uploadselectboxfield</repo>
<url type="discuss">http://symphony-cms.com/discuss/thread/41232/</url>
<types>
<type>Field</type>
Expand All @@ -20,8 +20,14 @@
<item type="image" url="http://symphonyextensions.com/nickdunn/uploadselectboxfield/media/uploadselectboxfield.png">Uploaded Files Select Box: Displays a select box list of files from a chosen folder</item>
</media>
<releases>
<release version="1.4.0" date="2018-03-22" min="2.3.x">
- Add empty `option` to be able to NOT select a file
<release version="1.3.3" date="2023-01-13" min="2.7.10">
- PHP 8.1 Fixes (may require PHP 7)
</release>
<release version="1.3.2" date="2020-03-09" min="2.3.x">
- Fix `Fatal error: [] operator not supported for strings in …`
</release>
<release version="1.3.1" date="2018-03-21" min="2.3.x">
- Add empty `option` to NOT select a file
</release>
<release version="1.3.0" date="2018-03-21" min="2.3.x">
- PHP7 Updates
Expand Down
29 changes: 15 additions & 14 deletions fields/field.uploadselectbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function canPrePopulate(){
return true;
}

public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = NULL, $entry_id = NULL) {
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null) {
if (!is_array($data) || empty($data)) return;

if (!is_array($data['file'])) {
Expand All @@ -55,11 +55,11 @@ public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = fa
$wrapper->appendChild($item);
}

function displaySettingsPanel(XMLElement &$wrapper, $errors = NULL){
function displaySettingsPanel(XMLElement &$wrapper, $errors = null){

Field::displaySettingsPanel($wrapper, $errors);

$div = new XMLElement('div', NULL, array('class' => 'group'));
$div = new XMLElement('div', null, array('class' => 'group'));

$ignore = array(
'/workspace/events',
Expand All @@ -68,7 +68,7 @@ function displaySettingsPanel(XMLElement &$wrapper, $errors = NULL){
'/workspace/pages',
'/workspace/utilities'
);
$directories = General::listDirStructure(WORKSPACE, NULL, 'asc', DOCROOT, $ignore);
$directories = General::listDirStructure(WORKSPACE, null, 'asc', DOCROOT, $ignore);

$label = Widget::Label(__('Destination Directory'));

Expand Down Expand Up @@ -98,7 +98,8 @@ function displaySettingsPanel(XMLElement &$wrapper, $errors = NULL){

}

function displayPublishPanel(XMLElement &$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL, $entry_id = NULL){
function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null){
$data['file'] = $data['file'] ?? null;
if(!is_array($data['file'])) $data['file'] = array($data['file']);

$options = array();
Expand All @@ -115,18 +116,18 @@ function displayPublishPanel(XMLElement &$wrapper, $data = NULL, $flagWithError
if($this->get('allow_multiple_selection') == 'yes') $fieldname .= '[]';

$label = Widget::Label($this->get('label'));
$label->appendChild(Widget::Select($fieldname, $options, ($this->get('allow_multiple_selection') == 'yes' ? array('multiple' => 'multiple') : NULL)));
$label->appendChild(Widget::Select($fieldname, $options, ($this->get('allow_multiple_selection') == 'yes' ? array('multiple' => 'multiple') : null)));

if($flagWithError != NULL) $wrapper->appendChild(Widget::wrapFormElementWithError($label, $flagWithError));
if($flagWithError != null) $wrapper->appendChild(Widget::wrapFormElementWithError($label, $flagWithError));
else $wrapper->appendChild($label);
}

function prepareTableValue($data, ?XMLElement $link = NULL, $entry_id = NULL){
function prepareTableValue($data, ?XMLElement $link = null, $entry_id = null){
$value = $data['file'];

if(!is_array($value)) $value = array($value);

$custom_link = "";
$custom_link[] = "";

foreach($value as $file) {
if($link){
Expand Down Expand Up @@ -221,11 +222,11 @@ function commit(){

}

public function processRawFieldData($data, &$status, &$message = NULL, $simulate = false, $entry_id = NULL){
public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null){
$status = self::__OK__;

if(!is_array($data)) return array('file' => General::sanitize($data));
if(empty($data)) return NULL;
if(empty($data)) return null;

$result = array('file' => array());
foreach($data as $file) {
Expand All @@ -237,9 +238,9 @@ public function processRawFieldData($data, &$status, &$message = NULL, $simulate
function createTable(){
return Symphony::Database()->query(
"CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') . "` (
`id` int(11) unsigned NOT NULL auto_increment,
`entry_id` int(11) unsigned NOT NULL,
`file` varchar(255) default NULL,
`id` int(11) unsigned NOT null auto_increment,
`entry_id` int(11) unsigned NOT null,
`file` varchar(255) default null,
PRIMARY KEY (`id`),
KEY `entry_id` (`entry_id`)
);"
Expand Down