Symfony embedRelation options - setting sub-form field visibility - symfony1

The prototype of embedRelation makes reference to an 'options' array (passed as $formArguments/$formargs).
Is it possible to pass an options array:
embedRelation("Model","ModelForm",$options_arr);
Where the options_arr contains form validator/widgets/etc to set for the relation?
$formargs['something']['publish_date'] = new sfWidgetFormInputText();
Or is it possible to limit the form fields displayed for a relation in a way like this?
$formargs['something']['use_fields'] = array('publish_date');
From sfFormDoctrine.class.php
...
* Embed a Doctrine_Collection relationship in to a form
*
* [php]
* $userForm = new UserForm($user);
* $userForm->embedRelation('Groups AS groups');
*
* #param string $relationName The name of the relation and an optional alias
* #param string $formClass The name of the form class to use
* #param array $formArguments Arguments to pass to the constructor (related object will be shifted onto the front)
* #param string $innerDecorator A HTML decorator for each embedded form
* #param string $decorator A HTML decorator for the main embedded form
*
* #throws InvalidArgumentException If the relationship is not a collection
*/
public function embedRelation($relationName, $formClass = null, $formArgs = array(), $innerDecorator = null, $decorator = null)
...
The closest I've been able to get to a spec for the $formArgs array() is from sfFormPropel.class.php (I'm using doctrine 1.2):
* `title`: The title of the collection form once embedded. Defaults to the relation name.
* `embedded_form_class`: The class name of the forms to embed. Uses the model name by default (a form based on a collection of Book objects embeds BookForm objects).
* `collection_form_class`: Class of the collection form to return. Defaults to sfFormPropelCollection.
* `hide_on_new`: If true, the relation form does not appear for new objects. Defaults to false.
* `add_empty`: Whether to allow the user to add new objects to the collection. Defaults to true.
* `add_delete`: Whether to add a delete widget for each object. Defaults to true.
* `remove_fields`: The list of fields to remove from the embedded object forms
* `item_pattern`: The pattern used to name each embedded form. Defaults to '%index%'.
If `add_empty` is set to `true`, the following additional options are available:
* `empty_label`: The label of the empty form. Defaults to 'new' + the relation name.
* `add_link`: The text of the JavaScript link that displays the empty form. Defaults to `Ann new`
* `max_additions`: The max number of additions accepted on the client side. Defaults to 0 (no limit)
If `add_delete` is set to `true`, the following additional options are available:
* `delete_name`: Name of the delete widget. Defaults to 'delete'.
* `delete_widget`: Optional delete widget object. If left null, uses a `sfWidgetFormDelete` instance, which is a checkbox widget with a Javascript confirmation.
* `alert_text`: The text of the Javascript alert to show.
* `hide_parent`: Whether to hide the deleted form when clicking the checkbox. Defaults to true.
* `parent_level`: The number of times parentNode must be called to reach the parent to hide. As a widget doesn't know if it's merged or embedded, this setting allows the JavaScript code used to hide the parent to find it. Recommended values: 6 for embedded form (default), 7 for merged form.
Any insight would be greatly appreciated.

I think that if you put say array('toto' => 'pwet') as form args, you will be able to retrieve 'pwet' in your form using $this->getOption('toto'); From there everything is possible (setting widgets and validators)

Why don't you go another way:
$o = $this->isNew() ? new Model() : $this->getObject()->getModel();
$model_form = new ModelForm($o);
//now configure widgets and validators
$model_form->setWidget('publish_date', new sfWidgetFormInputText());
$model_form->useFields(array('publish_date'));
$this->embedForm('Model', $model_form);

Related

How to Extract value from Parameter Key

I know its possible to read a parameter externally from the iFrame of the configurator
const frameColour = params.find(({ key }) => key === "frameColour");
but is it possible to on the ADD TO CART action to read the value of a Parameter Key (frameColour) and display it in an HTML DIV / Input? The reason for this is I have the parameter key that is the colour of the Shelf Frame I'm building, I want to be able to read the colour and display it to the Screen, then I can store that colour in my external database
After you've created a new configurator using the embedding API you can use this to get notified about parameter updates:
configurator.extended.callbacks.onUpdateParameters = (parameters) => {
// add your logic here
};
configurator.extended will give you access to the RoomleConfigurator instance (https://docs.roomle.com/web/api/classes/roomleconfigurator.html)

How to get format settings of field in drupal 8?

I have a drupal 8 project and I was requested by my customer to get format settings of field in content type to respond to an api for mobile app. I created a new module, and trying to get data of format settings. But haven't succeed. I just get all setting of a field, but not display settings of field in content type.
On picture below, I want get all data of format column, and show it as a json. Please help me. Thanks so much!
If you want to extract the formatter settings for a specific field, you can use this option:
/** #var \Drupal\Core\Entity\EntityDisplayRepository $entityDisplayRepository */
$entityDisplayRepository = \Drupal::service('entity_display.repository');
$productViewDisplay = $entityDisplayRepository->getViewDisplay('node', 'page', 'teaser' /* optional */);
$all_formatters_settings = $productViewDisplay->get('content');
$formatter_settings = $all_formatters_settings['field_my_field'];
If you need to get the settings for the widget, you can similarly call the function getFormDisplay in the repository instead of getViewDisplay:
/** #var \Drupal\Core\Entity\EntityDisplayRepository $entityDisplayRepository */
$entityDisplayRepository = \Drupal::service('entity_display.repository');
$productViewDisplay = $entityDisplayRepository->getFormDisplay('node', 'page', 'teaser' /* optional */);
$all_formatters_settings = $productViewDisplay->get('content');
$formatter_settings = $all_formatters_settings['field_my_field'];
There is another way to get the formatter settings.
$formatter_settings = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load("entity_type_id.entity_bundle.view_mode")
->getRenderer('field_logo_kataloga')
->getSettings();

How to get Customized template fields from invoice using QuickBooks QBFC

I want to get custom S.O. Invoice Template fields using QuickBooks QBFC.
Here's how to read custom fields from a sales order:
Add "0" to the OwnerIDList of the SalesOrderQuery.
Read custom header fields from the DataExtRetList that is attached to SalesOrderRet objects that are returned from the query.
Read custom line item fields from the DataExtRetList in the SalesOrderLineRet and SalesOrderLineGrouptRet objects that are included in each SalesOrderRet (if you're reading line items).
If you're already using the IncludeRetElementList, you must add DataExtRet to the list; if you're not then don't start using IncludeRetElementList until you have custom fields working. Just like any transaction query, you won't see any line item data unless you set the IncludeLineItems flag in the request.
Custom fields are well documented in the QuickBooks SDK Manual. I'd recommend you take a look at the section DataExt: Using Custom Fields and Private Data in the QBSDK Programmers Guide.
To elaborate on Paul Keister's answer, the reason you must add "0" to the query is because that is the Owner ID of the custom field you are attempting to retrieve. 0 is probably likely to be the value, but if the owner ID is different, you will have to use a different value here.
Some example C# code:
//set the owner id of the custom field you are trying to get back
IInvoiceQuery invoiceQuery = requestMsgSet.AppendInvoiceQueryRq();
invoiceQuery.OwnerIDList.Add("0");
//set up query parameters and actually call your query...
//call this method for each invoice to get its custom fields (if they exist)
static void GetInvoiceCustomFields(IInvoiceRet invoice)
{
if (invoice.DataExtRetList == null)
{
return;
}
for (int i = 0; i < invoice.DataExtRetList.Count; i++)
{
IDataExtRet extData = invoice.DataExtRetList.GetAt(i);
Console.WriteLine("external data name: " + extData.DataExtName.GetValue());
Console.WriteLine("external data value: " + extData.DataExtValue.GetValue());
}
}

how to validate and check if a entered URL is valid or not in Drupal 6

Without using any third party modules, is it possible to validate and check at the same time if any URL entered in a text-box is valid or not in Drupal 6 ? Some sample code will be appreciated.
menu_valid_path() function in menu.inc (which is part of Drupal Core) does just that.
To answer your specific question:
Without using any third party modules, is it possible to validate and check at the same time if any URL entered in a text-box is valid or not in Drupal 6
Yes.
You will, however, need to create a simple custom module.
Let's assume:
Your form id is my_form_1
The field name in question is my_path_field_1
In your MODULENAME.module file:
<?php
/**
* Modifies the existing form element 'my_path_field_1' to add
* 'MODULENAME_path_validate' function to validation array.
*
* (MYMODULE_path_validate is defined below)
*/
function MODULENAME_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'my_form_1' :
$form['my_path_field_1']['#element_validate'] = array('MODULENAME_path_validate');
break;
}
// Note, you could use hook_form_FORM_ID_alter(&$form, &$form_state)
// instead of the above to simplify things if the only thing this module
// does is validite one field for a valid path.
/**
* Validates the my_path_field_1 using Drupal's built-in menu_valid_path()
* function. Returns a form error if the field does not contain a valid path
* or the current user does not have access to the path's permission.
*/
function MODULENAME_path_validate($element, &$form_state) {
if (!menu_valid_path($element)) {
form_error($element, t('The path entered does not exist or you do not have permission to access it.'));
}
}

How to dynamically set Datatables search and column filters state via url params?

Let's say I have two models: customers and orders.
Every order belongs to a customer.
I also set a orders (index) view with a Datatable showing all the orders.
If I want to see all the orders for a given customer all I have to do is to filter the results for that customer writing the concerning customer name in the "search" field or selecting that customer from its column filter field.
Now I'd like to implement a customer-orders link which automatically shows the orders Datatable with those settings.
In other words, I'd like that a link to /orders?isearch='customer_name+customer_surname' will show the Datatable with the customer full name already written in the search field (or the customer column filter set accordingly).
Of course I can fetch the #customer instance variable from the controller and pass it to the view, but then?
Using the oSearch variable in the initialization code I can define an initialization value for the search field, the isearch variable:
$(document).ready( function() {
var isearch = $('#isearch').val()
$('#example').dataTable( {
"oSearch": {"sSearch": isearch}
} );
} )
The isearch value is stored in a proper hidden field in the view:
<%= hidden_field_tag "isearch", #isearch.to_s, { :id => "isearch" } %>
(This is the best way I found so far to pass an instance variable to a .js file in Rails).
Last but not least, the #isearch instance variable is set from the order_controller:
#isearch = params[:isearch]
Of course its value should be passed to the url like:
.../orders?isearch='customer_name+customer_surname'
----ADDENDUM----
I figured out I don't need an instance variable, in fact I can pass as many url params as I want using this javascript function:
function getUrlParam( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1].replace("+", " ");
}
Then I can fetch them from my .js file like this:
// fetches url params
var isearch = getUrlParam('isearch');
var customer_name = getUrlParam('customer_name');
var order_status = getUrlParam('order_status');
Accordin to these values I not only can set the oSearch variable but also a column-specific using Datatables aoSearchCols initialization parameter ( http://www.datatables.net/ref#aoSearchCols )
The last problem to solve, given that I am using individual column filtering with select elements (http://www.datatables.net/release-datatables/examples/api/multi_filter_select.html), so set every select element according to the URL-passed params.
I did it with this jQuery instruction:
// sets all select filters according to url passed params
$('select').val([customer_name, preparation_kind, preparation_status]);
From the performance point of view this solution is improvable, but its easy and it works.

Resources