Load an existing field in a custom module - programmatically-created

In drupal 8 (or 7?), is it possible to load programmatically an existing field ?
I mean :
from the drupal administration, I create a new custom content type with some fields. This fields have an unique machine name. I want create a form from a custom module. In this form, I want "load" the existing fields created in the custom content.
So, is it possible to load existing fields in a .php module ?

In case you want to build a custom form with field values of a created node, you can load the node programmatically with Node::load($nid) and put the the values in the render array. This way you need a predefined node you created yourself, because you call it using it's ID.

Related

Dynamic domain that gets list of saved asset queries as values?

Maximo 7.6.1.1:
I have a custom field in PMs called SAVEDASSETQUERY.
I would like to add a domain to this field that is a list of all saved asset queries that the user has access to.
It would be ideal if the domain were dynamic. If a new saved asset query were added to Maximo, then it would automatically show up in the domain/field in the PM application.
The reason for doing this is: I want to avoid data entry errors in the SAVEDASSETQUERY field.
Is it possible to do this with automation scripting, or would it require Java customization?
You could use a standard TABLE domain on the QUERY table object to achieve this. To filter on the user's queries (attribute OWNER), you would use the :&USERNAME& special bind variable.
Table domains:
https://www.ibm.com/support/pages/adding-lookup-functionality-field-maximo-using-table-domain
Bind variables:
https://www.ibm.com/support/pages/username-appname-and-other-special-bind-variables-you-can-use

Orchard CMS: Content Item Get Field By Name in View

I have created a custom content type (via the admin UI) that consists mostly of text fields. I know how to position the fields using zones and Placement.info but for simplicity I would like to use a single view template and to just arrange the fields by name instead of having to use Placement.info. Is there a good way to reference the fields by name from the content item in my MVC view?
So for example, I have a template named Content-MyContentType-Detail.cshtml. Instead of the generic
#Display(Model.Content)
I would like to be able to do something like
#Display(...MyField...)
#Display(...MyOtherField...)
Is there a way to explicitly render a field by name that is associated with my content item?
You can use Shape Tracing module to view model properties and how to get access to content parts.
Then in your template you can use something like this:
<h3>#Model.ContentItem.TitlePart.Title - £#Model.ContentItem.Product.Fields[1].Value</h3>
<p>#Model.ContentItem.BodyPart.Text</p>
If you don't just want to access the field's properties, but rather would like its shape rendered in-place, but like it would be when using placement (i.e. using the existing template), then read this article, which describes how to do direct rendering without placement: http://weblogs.asp.net/bleroy/archive/2013/02/13/easy-content-templates-for-orchard-take-2.aspx

OrchardCMS Custom Forms and lookup fields

I can create custom form with Orchard Custom forms Module based on a Content Type.
Also i can add Enumerable field to the Content Type to show as combo box in created custom form.
But i can set list items of the enumerable field statically only.
How can i set this items based on result of a projection query or fill the combo box by any content items of a special content type dynamically?
You can't out of the box.
You could write your own module that provided a query driven combo field, but if you've not written a module before then you might want to start with writing a more simple field module first.
You might find the following useful:
Creating a custom field tutorial
I'd also look at the Orchard Source code for the projection module to see how they use queries.

Custom Metadatafield in Document and Web content in Liferay

I want a metadata field getting values from database record. This metadata field should be added to document.
Can anyone provide a solution to my requirement.??
I presume you are using Liferay 6.1.
Web Content Structures
As for Web Content, you could programmatically create a JournalStructure (see JournalStuctureLocalServiceUtil) and populate the list of possible values for your structure field with values coming out of the database. You can put this "import code" inside a batch job, so your structure field and the values inside the external database are always in sync.
Document Metadata
How to do this with Metadata Sets is probably more interesting, as not only Dynamic Data Lists and Documents & Media use this in Liferay 6.1; as of 6.2, Web Content structures will utilize the same metadata API in favor of the old Journal API.
For this to implement, check out the xsd column of the DDMStructure table. It has more or less the same format as the XML for a JournalStructure, however there are more options available. Use DDMStructureLocalServiceUtil#addStructure to add such a new structure. Again, run this inside a batch so you always have the latest external DB values.

Web Part with a custom property bound to a "choice" field from a content type?

I'm trying to make a custom property for a WebPart. The custom property should be a drop down with choices coming from a "choice" column from a content type. Is that even possible?
You have two options:
1) If your choices will never change then you can hardcode an enum with these values and use that as datatype for your custom property. SP will the automatically generate a drop down.
2) If you can't hardcode the values then you have to implement what is called an EditorPart where you can code the UI for handling entry of the custom property
You cannot data bind directly to a content type column as it does not exist as in a bindable form, only as an XML secification on the content type itself.
Better to specify the column as a lookup and databind to the list directly. However, that is not going to work well when you only want one lookup across multiple webs or site collections.
In that case create a list in a config site such as http://intranet/sites/config and code a lookup control to databind to that list. Then use the control in the webpart and in a custom field control on the content type.
A bit of work, but worth it if you require SharePoint edit control (versioning, security etc) access to the contents of the lookup and a single (changeable) source of data across the entire site.

Resources