By AndyLicht on
Hi,
i want to generate a custom button, but i do not find a solution for my problem.
So i need a field with to values:
-label =>label
-value=>value
with these to parameters i can generate my button like:
label
the onclick-function is only the understanding my problem.
maybe someone can help me or knows a solution thanks a lot
Comments
So, now i am using field
I think i am only a few meters for the finish.
I am using the field collection and the template of the field collection.
So that is the original code of the template:
That is the code i am actually using:
The Problem is that the code is not really clean i am getting a lot of divs, thats look like:
<button type='button' value='<div class="field field-name-field-dienst field-type-text field-label-hidden"><div class="field-items"><div class="field-item even">Dienst</div></div></div>' /><div class="field field-name-field-beschriftung field-type-text field-label-hidden"><div class="field-items"><div class="field-item even">Hinzufügen</div></div></div></button>Waht can i do to get a clean code?
Thanks for helping me
Andy
---
For code questions you would have better luck moving this to the module development forum.
You shouldn't use the render
You shouldn't use the render function when creating the value / label for the button.
I guess $content is an entity object or something like that?
If that's the case, you could access the raw values like this:
or
Hi thanks for helping
Hi thanks for helping me.
Both variants give me an empty button. So i am getting:
<button type='button' value='' /></button>by the first methode i get these error:
Notice: Undefined index: und in include() (Zeile 36 von C:\xampp\htdocs\geoportal_drupal_test\sites\all\modules\field_collection\field-collection-item.tpl.php).
Notice: Undefined index: und in include() (Zeile 37 von C:\xampp\htdocs\geoportal_drupal_test\sites\all\modules\field_collection\field-collection-item.tpl.php).
thanks for helping me.
Okay, could you then post the
Okay, could you then post the contents of $content? (var_dump($content); )
Hi,the var_dump promts me
Hi,
the var_dump promts me the following output:array(2)
{
["field_label"]=> array(18)
{
["#theme"]=> string(5) "field"
["#weight"]=> string(1) "0"
["#title"]=> string(5) "Label"
["#access"]=> bool(true)
["#label_display"]=> string(6) "hidden"
["#view_mode"]=> string(4) "full"
["#language"]=> string(3) "und"
["#field_name"]=> string(11) "field_label"
["#field_type"]=> string(4) "text"
["#field_translatable"]=> string(1) "0"
["#entity_type"]=> string(21) "field_collection_item"
["#bundle"]=> string(12) "field_button"
["#object"]=> object(FieldCollectionItemEntity)#56 (21)
{
["fieldInfo":protected]=> NULL
["hostEntity":protected]=> object(stdClass)#58 (29)
{
["vid"]=> string(1) "4"
["uid"]=> string(1) "1"
["title"]=> string(8) "WMS Test"
["log"]=> string(0) ""
["status"]=> string(1) "1"
["comment"]=> string(1) "2"
["promote"]=> string(1) "1"
["sticky"]=> string(1) "0"
["nid"]=> string(1) "4"
["type"]=> string(3) "wms"
["language"]=> string(2) "de"
["created"]=> string(10) "1376022424"
["changed"]=> string(10) "1376022424"
["tnid"]=> string(1) "0"
["translate"]=> string(1) "0"
["revision_timestamp"]=> string(10) "1376022424"
["revision_uid"]=> string(1) "1"
["field_button"]=> array(1)
{
["und"]=> array(1)
{
[0]=> array(2)
{
["value"]=> string(1) "1"
["revision_id"]=> string(1) "1"
}
}
}
["body"]=> array(0)
{
}
["rdf_mapping"]=> array(9)
{
["rdftype"]=> array(2)
{
[0]=> string(9) "sioc:Item"
[1]=> string(13) "foaf:Document"
}
["title"]=> array(1)
{
["predicates"]=> array(1)
{
[0]=> string(8) "dc:title"
}
}
["created"]=> array(3)
{
["predicates"]=> array(2)
{
[0]=> string(7) "dc:date"
[1]=> string(10) "dc:created"
}
["datatype"]=> string(12) "xsd:dateTime"
["callback"]=> string(12) "date_iso8601"
}
["changed"]=> array(3)
{
["predicates"]=> array(1)
{
[0]=> string(11) "dc:modified"
}
["datatype"]=> string(12) "xsd:dateTime"
["callback"]=> string(12) "date_iso8601"
}
["body"]=> array(1)
{
["predicates"]=> array(1)
{
[0]=> string(15) "content:encoded"
}
}
["uid"]=> array(2)
{
["predicates"]=> array(1)
{
[0]=> string(16) "sioc:has_creator"
}
["type"]=> string(3) "rel"
}
["name"]=> array(1)
{
["predicates"]=> array(1)
{
[0]=> string(9) "foaf:name"
}
}
["comment_count"]=> array(2)
{
["predicates"]=> array(1)
{
[0]=> string(16) "sioc:num_replies"
}
["datatype"]=> string(11) "xsd:integer"
}
["last_activity"]=> array(3)
{
["predicates"]=> array(1)
{
[0]=> string(23) "sioc:last_activity_date"
}
["datatype"]=> string(12) "xsd:dateTime"
["callback"]=> string(12) "date_iso8601"
}
}
["cid"]=> string(1) "0"
["last_comment_timestamp"]=> string(10) "1376022424"
["last_comment_name"]=> NULL ["last_comment_uid"]=> string(1) "1"
["comment_count"]=> string(1) "0"
["name"]=> string(11) "balschmiter"
["picture"]=> string(1) "0"
["data"]=> string(4) "b:0;"
["entity_view_prepared"]=> bool(true)
}
["hostEntityId":protected]=> int(4)
["hostEntityRevisionId":protected]=> bool(false)
["hostEntityType":protected]=> string(4) "node"
["langcode":protected]=> string(3) "und"
["item_id"]=> string(1) "1"
["revision_id"]=> string(1) "1"
["field_name"]=> string(12) "field_button"
["default_revision"]=> bool(true)
["archived"]=> string(1) "0"
["entityType":protected]=> string(21) "field_collection_item"
["entityInfo":protected]=> array(21)
{
["label"]=> string(21) "Field collection item"
["label callback"]=> string(18) "entity_class_label"
["uri callback"]=> string(16) "entity_class_uri"
["entity class"]=> string(25) "FieldCollectionItemEntity"
["controller class"]=> string(19) "EntityAPIController"
["base table"]=> string(21) "field_collection_item"
["revision table"]=> string(30) "field_collection_item_revision"
["fieldable"]=> bool(true)
["redirect"]=> bool(false)
["entity keys"]=> array(3)
{
["id"]=> string(7) "item_id"
["revision"]=> string(11) "revision_id"
["bundle"]=> string(10) "field_name"
}
["module"]=> string(16) "field_collection"
["view modes"]=> array(1)
{
["full"]=> array(2)
{
["label"]=> string(21) "Vollständiger-Inhalt"
["custom settings"]=> bool(false)
}
}
["access callback"]=> string(28) "field_collection_item_access"
["metadata controller class"]=> string(37) "FieldCollectionItemMetadataController"
["bundles"]=> array(1)
{
["field_button"]=> array(3)
{
["label"]=> string(29) "Field collection field_button"
["admin"]=> array(4)
{
["path"]=> string(62) "admin/structure/field-collections/%field_collection_field_name"
["real path"]=> string(46) "admin/structure/field-collections/field-button"
["bundle argument"]=> int(3)
["access arguments"]=> array(1)
{
[0]=> string(28) "administer field collections"
}
}
["rdf_mapping"]=> array(0)
{
}
}
}
["static cache"]=> bool(true)
["field cache"]=> bool(true)
["load hook"]=> string(26) "field_collection_item_load"
["translation"]=> array(0)
{
}
["schema_fields_sql"]=> array(2)
{
["base table"]=> array(4)
{
[0]=> string(7) "item_id"
[1]=> string(11) "revision_id"
[2]=> string(10) "field_name"
[3]=> string(8) "archived"
}
["revision table"]=> array(2)
{
[0]=> string(11) "revision_id"
[1]=> string(7) "item_id"
}
}
["configuration"]=> bool(false)
}
["idKey":protected]=> string(7) "item_id"
["nameKey":protected]=> string(7) "item_id"
["statusKey":protected]=> string(6) "status"
["defaultLabel":protected]=> bool(false)
["field_value"]=> array(1)
{
["und"]=> array(1)
{
[0]=> array(3)
{
["value"]=> string(195) "http://mapserver.lgb-rlp.de/cgi-bin/wlf_gwe?SERVICE=WMS&VERSION=1.1.1&ST..."
["format"]=> NULL
["safe_value"]=> string(231) "http://mapserver.lgb-rlp.de/cgi-bin/wlf_gwe?SERVICE=WMS&VERSION=1.1.1&ST..."
}
}
}
["field_label"]=> array(1)
{
["und"]=> array(1)
{
[0]=> array(3)
{
["value"]=> string(11) "Hinzufügen"
["format"]=> NULL
["safe_value"]=> string(11) "Hinzufügen"
}
}
}
["rdf_mapping"]=> array(0)
{
}
["entity_view_prepared"]=> bool(true)
}
["#items"]=> array(1)
{
[0]=> array(3)
{
["value"]=> string(11) "Hinzufügen"
["format"]=> NULL
["safe_value"]=> string(11) "Hinzufügen"
}
}
["#formatter"]=> string(12) "text_default"
[0]=> array(1)
{
["#markup"]=> string(11) "Hinzufügen"
}
["#printed"]=> bool(true)
["#children"]=> string(160) "Hinzufügen"
}
["field_value"]=> array(18)
{
["#theme"]=> string(5) "field"
["#weight"]=> string(1) "1"
["#title"]=> string(5) "Value"
["#access"]=> bool(true)
["#label_display"]=> string(6) "hidden"
["#view_mode"]=> string(4) "full"
["#language"]=> string(3) "und"
["#field_name"]=> string(11) "field_value"
["#field_type"]=> string(4) "text"
["#field_translatable"]=> string(1) "0"
["#entity_type"]=> string(21) "field_collection_item"
["#bundle"]=> string(12) "field_button"
["#object"]=> object(FieldCollectionItemEntity)#56 (21)
{
["fieldInfo":protected]=> NULL
["hostEntity":protected]=> object(stdClass)#58 (29)
{
["vid"]=> string(1) "4"
["uid"]=> string(1) "1"
["title"]=> string(8) "WMS Test"
["log"]=> string(0) ""
["status"]=> string(1) "1"
["comment"]=> string(1) "2"
["promote"]=> string(1) "1"
["sticky"]=> string(1) "0"
["nid"]=> string(1) "4"
["type"]=> string(3) "wms"
["language"]=> string(2) "de"
["created"]=> string(10) "1376022424"
["changed"]=> string(10) "1376022424"
["tnid"]=> string(1) "0"
["translate"]=> string(1) "0"
["revision_timestamp"]=> string(10) "1376022424"
["revision_uid"]=> string(1) "1"
["field_button"]=> array(1)
{
["und"]=> array(1)
{
[0]=> array(2)
{
["value"]=> string(1) "1"
["revision_id"]=> string(1) "1"
}
}
}
["body"]=> array(0)
{
}
["rdf_mapping"]=> array(9)
{
["rdftype"]=> array(2)
{
[0]=> string(9) "sioc:Item"
[1]=> string(13) "foaf:Document"
}
["title"]=> array(1)
{
["predicates"]=> array(1)
{
[0]=> string(8) "dc:title"
}
}
["created"]=> array(3)
{
["predicates"]=> array(2)
{
[0]=> string(7) "dc:date"
[1]=> string(10) "dc:created"
}
["datatype"]=> string(12) "xsd:dateTime"
["callback"]=> string(12) "date_iso8601"
}
["changed"]=> array(3)
{
["predicates"]=> array(1)
{
[0]=> string(11) "dc:modified"
}
["datatype"]=> string(12) "xsd:dateTime"
["callback"]=> string(12) "date_iso8601"
}
["body"]=> array(1)
{
["predicates"]=> array(1)
{
[0]=> string(15) "content:encoded"
}
}
["uid"]=> array(2)
{
["predicates"]=> array(1)
{
[0]=> string(16) "sioc:has_creator"
}
["type"]=> string(3) "rel"
}
["name"]=> array(1)
{
["predicates"]=> array(1)
{
[0]=> string(9) "foaf:name"
}
}
["comment_count"]=> array(2)
{
["predicates"]=> array(1)
{
[0]=> string(16) "sioc:num_replies"
}
["datatype"]=> string(11) "xsd:integer"
}
["last_activity"]=> array(3)
{
["predicates"]=> array(1)
{
[0]=> string(23) "sioc:last_activity_date"
}
["datatype"]=> string(12) "xsd:dateTime"
["callback"]=> string(12) "date_iso8601"
}
}
["cid"]=> string(1) "0"
["last_comment_timestamp"]=> string(10) "1376022424"
["last_comment_name"]=> NULL
["last_comment_uid"]=> string(1) "1"
["comment_count"]=> string(1) "0"
["name"]=> string(11) "balschmiter"
["picture"]=> string(1) "0"
["data"]=> string(4) "b:0;"
["entity_view_prepared"]=> bool(true)
}
["hostEntityId":protected]=> int(4)
["hostEntityRevisionId":protected]=> bool(false)
["hostEntityType":protected]=> string(4) "node"
["langcode":protected]=> string(3) "und"
["item_id"]=> string(1) "1"
["revision_id"]=> string(1) "1"
["field_name"]=> string(12) "field_button"
["default_revision"]=> bool(true)
["archived"]=> string(1) "0"
["entityType":protected]=> string(21) "field_collection_item"
["entityInfo":protected]=> array(21)
{
["label"]=> string(21) "Field collection item"
["label callback"]=> string(18) "entity_class_label"
["uri callback"]=> string(16) "entity_class_uri"
["entity class"]=> string(25) "FieldCollectionItemEntity"
["controller class"]=> string(19) "EntityAPIController"
["base table"]=> string(21) "field_collection_item"
["revision table"]=> string(30) "field_collection_item_revision"
["fieldable"]=> bool(true)
["redirect"]=> bool(false)
["entity keys"]=> array(3)
{
["id"]=> string(7) "item_id"
["revision"]=> string(11) "revision_id"
["bundle"]=> string(10) "field_name"
}
["module"]=> string(16) "field_collection"
["view modes"]=> array(1)
{
["full"]=> array(2)
{
["label"]=> string(21) "Vollständiger-Inhalt"
["custom settings"]=> bool(false)
}
}
["access callback"]=> string(28) "field_collection_item_access"
["metadata controller class"]=> string(37) "FieldCollectionItemMetadataController"
["bundles"]=> array(1)
{
["field_button"]=> array(3)
{
["label"]=> string(29) "Field collection field_button"
["admin"]=> array(4)
{
["path"]=> string(62) "admin/structure/field-collections/%field_collection_field_name"
["real path"]=> string(46) "admin/structure/field-collections/field-button"
["bundle argument"]=> int(3)
["access arguments"]=> array(1)
{
[0]=> string(28) "administer field collections"
}
}
["rdf_mapping"]=> array(0)
{
}
}
}
["static cache"]=> bool(true)
["field cache"]=> bool(true)
["load hook"]=> string(26) "field_collection_item_load"
["translation"]=> array(0)
{
}
["schema_fields_sql"]=> array(2)
{
["base table"]=> array(4)
{
[0]=> string(7) "item_id"
[1]=> string(11) "revision_id"
[2]=> string(10) "field_name"
[3]=> string(8) "archived"
}
["revision table"]=> array(2)
{
[0]=> string(11) "revision_id"
[1]=> string(7) "item_id"
}
}
["configuration"]=> bool(false)
}
["idKey":protected]=> string(7) "item_id"
["nameKey":protected]=> string(7) "item_id"
["statusKey":protected]=> string(6) "status"
["defaultLabel":protected]=> bool(false)
["field_value"]=> array(1)
{
["und"]=> array(1)
{
[0]=> array(3)
{
["value"]=> string(195) "http://mapserver.lgb-rlp.de/cgi-bin/wlf_gwe?SERVICE=WMS&VERSION=1.1.1&ST..."
["format"]=> NULL
["safe_value"]=> string(231) "http://mapserver.lgb-rlp.de/cgi-bin/wlf_gwe?SERVICE=WMS&VERSION=1.1.1&ST..."
}
}
}
["field_label"]=> array(1)
{
["und"]=> array(1)
{
[0]=> array(3)
{
["value"]=> string(11) "Hinzufügen"
["format"]=> NULL
["safe_value"]=> string(11) "Hinzufügen"
}
}
}
["rdf_mapping"]=> array(0)
{
}
["entity_view_prepared"]=> bool(true)
}
["#items"]=> array(1)
{
[0]=> array(3)
{
["value"]=> string(195) "http://mapserver.lgb-rlp.de/cgi-bin/wlf_gwe?SERVICE=WMS&VERSION=1.1.1&ST..."
["format"]=> NULL
["safe_value"]=> string(231) "http://mapserver.lgb-rlp.de/cgi-bin/wlf_gwe?SERVICE=WMS&VERSION=1.1.1&ST..."
}
}
["#formatter"]=> string(12) "text_default"
[0]=> array(1)
{
["#markup"]=> string(231) "http://mapserver.lgb-rlp.de/cgi-bin/wlf_gwe?SERVICE=WMS&VERSION=1.1.1&ST..."
}
["#printed"]=> bool(true)
["#children"]=> string(380) "http://mapserver.lgb-rlp.de/cgi-bin/wlf_gwe?SERVICE=WMS&VERSION=1.1.1&ST..."
}
}
Please wrap your code in
Please wrap your code in <code></code> tags.
So, what exactly is it that you are trying to do?
Contact me to contract me for D7 -> D10/11 migrations.
Did you place your var_dump()
Did you place your var_dump() at the same place you placed your code?
cause there is no reference to field_beschriftung and field_dienst.
can you just do a var_dump of $content['field_beschriftung'] and $content['field_dienst'];
like this:
I am sorry, i have chenged it
I am sorry, i have changed it to field_label and field_value. Thanks for helping me.
And sorry, next time i will put it into the code-tags
Here is the solution:
The problem was, that the content-array contains an object, so you have to convert it, or use some other php functions. The solution shows the problem.
Thanks for helping me!!!!!