Argument 1 passed to must be of the type string, array given - typo3

I have a TYPO3 php function to get a preselected categories,
The error generated in frontend say that it should be a String but an array is given:
Argument 1 passed to Web\Auf\Controller\ResultsController::getPreselectedCategories() must be of the type string, array given, called in /app/Private/typo3conf/ext/auf/Classes/Controller/DemandRequestTrait.php on line 93
The part of the code called :
protected function getPreselectedStandardCategories(): array
{
return $this->getPreselectedCategories($this->settings['filter']['category']['preselected'] ?? '');
}
Please forgive if this is not clear ask me to explain more or to fix.

Thank you very much for your answers.
The issue was due to wrong Flexform configuration stored in the database,
When the backend user change the type of content element the flexform still stored.
I have deleted the content element and i have created a new one. This fixed my problem.

Related

FindBy property in TYPO3 Extbase MVC is not working

I'm unable to run the FindBy magic function property in Extbase MVC
$title=array(0 =>'Books Day');
$each_event=$this->eventRepository->findByTitle($title);
$each_event is returning an object of type TYPO3\CMS\Extbase\Persistence\Generic\QueryResult .
How do I make this work?
I also tried passing in a string to findByTitle and findByOne. Both don;t work! :(
I'm using TYPO3 6.1 and extension builder.
The last part of those magic functions always needs to be a field in the database. So "title" must be in your model. You might have a field "one" for your object, but I guess you meant findOneByTitle?
The object type QueryResult is correct. You can turn it into an array for debugging purpose for example:
$foo = $query->execute()->toArray();
By the way: check wether your eventRepository is null or not and you could try this to see if it works at all:
$result = $this->myRepository->findAll();
Try
$each_event=$this->eventRepository->findByTitle($title)->toArray();
Reference to the QueryResult.
As said in the documentation, it returns a QueryResultInterface|array.
As a consequence you have to loop over the result like this:
foreach($each_event as $single_event) {
$single_event->getProperty();
}
If you are sure that it returns only one single value you could also access it by the index 0:
$each_event[0]->getProperty();

Query criteria: from public variable or from form

After a few hours searching, I couldn't find any solution to this little problem I'm having.
I have a query that retrieves one of its criteria from a form. I have referenced correctly the value on the form from the query, and it works, but what I wanted to do is a bit more complicated: when the form is closed, I want to launch the query with a "default value".
I tried to do it in 2 different ways:
a) Defining an "IIf" at the query criteria: I would need a function that checks if the form from which I retrieve the values is open.
b) Defining public variables with a default value, which would be changed from the form: I don't know where/when to initialize the value of the variable.
Does anyone have a better idea on how to do this?
TL;DR: Query gets criteria from form when it's open. If form is closed, query uses default value. HELP!
You can create a VBA function in a module to do this :
Function MyCriterion() As Long
MyCriterion = 1234 ' default value
If CurrentProject.AllForms("MyForm").IsLoaded Then
MyCriterion = Forms("MyForm").MyControl.Value
End If
End Function

Get statuscode text in C#

I'm using a plugin and want to perform an action based on the records statuscode value. I've seen online that you can use entity.FormattedValues["statuscode"] to get values from option sets but when try it I get an error saying "The given key was not present in the dictionary".
I know this can happen when the plugin cant find the change for the field you're looking for, but i've already checked that this does exist using entity.Contains("statuscode") and it passes by that fine but still hits this error.
Can anyone help me figure out why its failing?
Thanks
I've not seen the entity.FormattedValues before.
I usually use the entity.Attributes, e.g. entity.Attributes["statuscode"].
MSDN
Edit
Crm wraps many of the values in objects which hold additional information, in this case statuscode uses the OptionSetValue, so to get the value you need to:
((OptionSetValue)entity.Attributes["statuscode"]).Value
This will return a number, as this is the underlying value in Crm.
If you open up the customisation options in Crm, you will usually (some system fields are locked down) be able to see the label and value for each option.
If you need the label, you could either do some hardcoding based on the information in Crm.
Or you could retrieve it from the metadata services as described here.
To avoid your error, you need to check the collection you wish to use (rather than the Attributes collection):
if (entity.FormattedValues.Contains("statuscode")){
var myStatusCode = entity.FormattedValues["statuscode"];
}
However although the SDK fails to confirm this, I suspect that FormattedValues are only ever present for numeric or currency attributes. (Part-speculation on my part though).
entity.FormattedValues work only for string display value.
For example you have an optionset with display names as 1, 2, 3,
The above statement do not recognize these values because those are integers. If You have seen the exact defintion of formatted values in the below link
http://msdn.microsoft.com/en-in/library/microsoft.xrm.sdk.formattedvaluecollection.aspx
you will find this statement is valid for only string display values. If you try to use this statement with Integer values it will throw key not found in dictionary exception.
So try to avoid this statement for retrieving integer display name optionset in your code.
Try this
string Title = (bool)entity.Attributes.Contains("title") ? entity.FormattedValues["title"].ToString() : "";
When you are talking about Option set, you have value and label. What this will give you is the label. '?' will make sure that the null value is never passed.

Symfony2 error message in the input field

I would like to display error message in the field it is for. I know how to put the error message into the field, but I want to find a dynamic way to check after re-submittion, if the inserted value is not the error message itself. I use doctrine annotations.
For example if the field is "title", the error message would be "The title must be filled!".
So the title field is not empty anymore, I click submit again, and it is valid now. I don't want to check every single field like
if $entity->getTitle() == "The title must be filled" ...
I've managed to do this with not displayed error divs in the twig, and jquery, but I want to know if there is a better way to do this from the controller? Thanks
You're asking how to correctly do something the wrong way... If the input value is not the value you want processed, it should have never been the value to begin with. That being said, I'm sure you have your reasons...
You need to listen to FormEvents::BIND_CLIENT_DATA and clear the form data if it matches your error string.
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('title');
$builder->get('title')->addEventListener(
FormEvents::BIND_CLIENT_DATA,
function(FilterDataEvent $event)
{
if ('The title must be filled' == $event->getData()) {
$event->setData('');
}
},
);
If you want to apply this behavior globally you need to attach this listener using a form type extension that extends 'field'. You will also need to introspect all of the possible validation error messages for the current field using the validator and pass these through the translator, then compare the results with the event data.

JQuery UI Autocomplete returning all values

I have the following code:
$("#auto").autocomplete({
source: "js/search.php",
minLength: "3" });
This code is assign to an input text box where i type a name and after 3 letters it should return the ones that have similar letters. For my case it is returning all values, even those not related to the 3 letters already typed. My question is:
How to send my search.php file the value inside the input so it should know what to search for. For the moment it searches for everything. I checked the value that was going to php and it was empty. Since the query to mysql uses LIKE '%VARIABLE%' and the variable is empty it searches for '%%' which is all cases.
How can i send the correct informacion from JS to PHP with the simplest form.
Here is the explanation :
http://www.simonbattersby.com/blog/jquery-ui-autocomplete-with-a-remote-database-and-php/
Regards