spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

How to extract factory-friendly form element configuration array from an existing element instance in ZF2?


The short answer is no; you will have to roll your own.

You could create a independent class that can take any element and return the correct array by reading it's public methods; this is effectively reversing the functionality of the FormFactory.

A very brief example

class FormElementSerializer
{
    public function toArray(ElementInterface
$element)
    {
        $spec =
$this->getElementSpec($element);

        if ($element instanceof FieldsetInterface)
{
            $spec =
$this->getFieldsetSpec($element, $spec);
        }

        if ($element instanceof Form) {
            $spec =
$this->getFormSpec($element, $spec);
        }

        return $spec;
    }

    protected function
getElementSpec(ElementInterface $element)
    {
        $spec = array(
            'type' =>
$this->getElementType($element),
            'name' => $element->getName(),
            'options' =>
$element->getOptions(),
            'attributes' =>
$element->getAttributes(),
        );
        return $spec;
    }

    protected function
getFieldsetSpec(FieldsetInterface $fieldset, array
$spec)
    {
        foreach($fieldset->getElements() as
$element) {
            $spec['elements'][] =
$this->getElementSpec($element);
        }
        return $spec;
    }

    // deals with hydrators, fieldsets etc
    protected function getFormSpec(FormInterface
$form, array $spec);

    // could be as simple as returning the class
name
    protected function
getElementType(ElementInterface $element);
} 

Categories : PHP

Related to : How to extract factory-friendly form element configuration array from an existing element instance in ZF2?
How to check a select element change when the element name is an array
Ok, as I said, ids should be unique for a page, so for similar items you should use classes: .... <select class="item" name="lines[2][item]"></select> <input class="unit" name="lines[2][unit]" /> <input class="price" name="lines[2][price]" /> <input class="total" name="lines[2][total]" /> .... So, for change event use something like jQuery('.item').change(functio

Categories : PHP
Extract XML element value from a RSS feed
To retrieve the pubDate content you can use the casper.fetchText function, but it has a drawback that it concatenates all text nodes into one string: casper.echo(casper.fetchText("pubDate")); would print Fri, 21 Nov 2014 00:56:15 -0500Fri, 21 Nov 2014 00:47:34 -0500Fri, 21 Nov 2014 00:45:36 -0500 To actually retrieve the text separately you can use casper.getElementsInfo which works on m

Categories : Javascript
C++: Extract size of boost::variant element
You can do that in the visitor, something like following : /* template <typename T> using EnableIf = typename std::enable_if< std::is_pod<T>::value >::type* ; */ struct visit: public boost::static_visitor<> { visit( ): size(0) { } template<typename T /*, EnableIf<T> = nullptr */ > void operator()( T& x) const { size += sizeof ( x

Categories : C++
Is it possible to get the annotated element from an annotation instance?
No. :) It appears to be a one way reference. I assume you want to pass the annotation to some other code which would then need to know what it was applied to? When you extract the annotations from the annotated element, you would store the field, method etc with the annotation at that time. Perhaps create a wrapper bean which contains the Annotation and the annotated element. Or, if the origina

Categories : Java
Adding a script element to an existing TWebBrowser document
Here' a complete example how to use IHtmlScriptElement. Html is loaded at application startup. The code under Button1Click adds the javascript to the DOM and executes it: unit u_frm_SO27091639; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, OleCtrls, SHDocVw, MsHtml, ActiveX; type TForm1 = class(TForm) WebBrowser1: TWebBro

Categories : Javascript
Recently Add
Cartesian product of associative array showing key and value - PHP
Datamapper orm save and update not working
find methods in COM object
PHP Keyword search not working with multiple words
Set a total based on items ordered, two types, and sometimes one type will not be ordered.
FB request to join a group, going around their official SDK
Using Google charts with php data?
OAuth2 integration with ExactOnline
libvirt-php receives the error: unable to connect to server Permission denied
How to echo results by sets of 2?
Why does PHP's sprintf not round 5s reliably?
php replace affects on replaced string
PHP Find and replace multiple similar entries
Replace PHP date output with pre-made images
How to install Laravel 4 packages on Windows
Using updateOrCreate for multiple data insert in Laravel
Storing products in a MYSQL database and then search and filter them?
Create order with PrestaShop's API
how to get latest messages from all users
Yii CMultiFileUpload Restrict Image width
Combine array by key factor
Semicolon after if condition in PHP - code still works
Get date using day of the week
soap web service with symfony
Seasonal Reservation system Day/month
is it possible to join a single table it self?
Attempting to compare two arrays PHP
Sticky Select Option
Eventbrite duplicate event entry
Pagination Not Working on custom post type in Wordpress
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.