How to edit one-to-one related model in an admin tab - relationship

How can I present a one-to-one related object for editing in the same admin, as a new tab?
I have two models related one-to-one: Lorem and Ipsum. Each declares a $has_one relationship with the other.
There is a LoremAdmin that declares $managed_models = array('Lorem' => […]). Should that also include 'Ipsum', to have the same admin manage the related model too?
The LoremAdmin currently presents only a select field (on its “main” tab) for existing Ipsum instances. Instead, I want:
Creating a Lorem also creates an Ipsum.
The “main” tab contains nothing about Ipsum; instead, all the Ipsum fields are on an Ipsum tab of the LoremAdmin.
How can I convince the LoremAdmin to do that?
(The site is using SilverStripe 3, if it matters.)

Related

Dynamic Single page application UI editor for simple business object entites

We have many "Configuration Entities" in our system. For example: list of banks, list of countries etc. Each list contain up to 100 items all from the same object model.
For example: Bank {account number, bank name, bank description}
We would like to build generic/dynamic editor that will contain:
grid view: a tabular view that show the list of items (add, edit, delete buttons) with pagination, sorting and search.
edit entity view: enable to edit the entity properties (with input validation).
We want to use it to edit all our different "Configuration Entities" with minimum work/boilerplate for adding new entities.
So I was thinking that we need entity descriptor (the entity properties, metadata and validation, rest API metadata, etc.) that will be the input for this module - then the module will be built dynamically.
Is there any already exists open source that I can use (in Vue or React) or should I build it from scratch?

Drupal 7: Can a module create a custom entity type and also custom fields it uses?

I wrote a Drupal 7 module which defines a new entity type with hook_entity_info() et al. and several custom field types with hook_field_info() et al. that are required by this entity. When the module is installed and enabled it is impossible to disable it because there is a circular dependency, the entity requires the fields that it defines. Is there a way around this that I'm missing? Or do I need to break this into two modules, one for the field and one for the entity?
I think that, when you disable your module, you have to kill the instance of field on your node type before disabling it.
Try this to delete instance of fields:
$field_instance_to_delete = field_info_instance('node', $field_name, $nodetype);
field_delete_instance($field_instance_to_delete );

Drupal 7: Feeds doesn't assign feed items to organic group

I installed "Organic Groups" and "Feeds". I have 2 content type (feeds and articles).
Feeds works fine, it imports the items well.
I assign feeds and articles content to a group (both have group reference field), but when I import with Feeds, the items doesn't have group reference.
I tried to configure the importer, but I can not map the reference group.
Any idea? Thanks ^^
(Sorry for my english)
I know this is an old post, but I think I have a solution (I had a similar experience earlier). It's a little complicated, but it definitely works!
Install both [Feeds] (https://www.drupal.org/project/feeds) and [Feeds Tamper] (https://www.drupal.org/project/feeds_tamper)
Create a content type to receive the feed entries.
*I'll call this new content type "Blog post"
Add a text field to BOTH the new content type AND to your OG form.
*I'll call this field "Feed nickname"
On your OG form, fill in the field with the appropriate feed nickname.
*I suggest making this a one-word nickname
Under Structure>Feeds Importers>Edit>Node processor settings, select "Blog post" as the chosen bundle to receive the feed. Click save.
Under Structure>Feeds Importers>Edit>Node processor mapping, add a new mapping with "Blank source" as the source and "Feed nickname" as the target. Click save.
Under Structure>Feeds Importers>Tamper, scroll to the section "Blank source-> Feed nickname" and click "add plugin."
Choose the plugin called "Set default value" and set the default value to your chosen feed nickname. Click save and make sure the plugin is enabled. Click save at the bottom of the tamper form.
Add the feed importer as usual, under yoursite.org/import
Short explanation:
What this process does, essentially, is to assign all of the incoming feeds a default dummy value (in this case, the "feed nickname" you chose), and then match that value to the one you put in your content type. Having the same field and field value shared among the feed, the content type, and the OG links them together, and makes it possible for you to relate them in Views, etc.
Hope this helps!

When creating a Drupal 7 content type programmatically, is there a way to add tuples of fields?

In Drupal 7, I'd like to create a Person content type. A person may have multiple profiles - an administrator should be able to select which profile will be considered the primary one. So, that means that I need a tuple consisting of:
A textarea, for the profile text
A checkbox, indicating that this is the primary profile
A textbox, for naming this particular profile
I need functionality to behave like that of any of the lists: I can click "Add another Item", and a set of all three of these fields will appear.
I have a vague idea of how this can be executed, but it involves using the form API to add fields before the form renders each time, as well as the necessary AJAX behavior. This seems a bit overcomplicated, since this would also necessitate creating an additional DB table to hold these tacked-on fields.
Is there a relatively simple way of doing this solely through hook_install()?
You can use drupal.org/project/profile2 or you can complete it using standard Drupal functionality, i.e. create a content type named, let's say, 'myprofile' and add all the fields use need. Then add a nodereferece (http://drupal.org/project/references) field to the user standard profie that would point to your 'myprofile' content type.
So all the 'myprofile' content, created by that user would be his profiles and the one pointed in his standard profile will be his default.
I hope it's clear enough )

Multiselect Form Field in PDF

Using PDF, is it possible to create a single form element with multiple fields of which several can be selected? For example, in HTML, one can create a set of checkboxes associated with the same field name:
<div>Select one for Member of the School Board</div>
<input type="checkbox" name="field(school)" value="vote1">
<span class="label">Libby T. Garvey</span><br/>
<input type="checkbox" name="field(school)" value="vote2">
<span class="label">Emma N. Violand-Sanchez</span><br/>
In this case, the field name is "field(school)", and when the form is submitted, "field(school)" can be supplied 0, 1, or 2 times.
Is there an equivalent construct in PDF where a single field can have multiple values. So far in my investigation, it appears that if fields are assigned the same name, it is only possible to select one field. If it is possible to implement this in PDF, what is this construct called and how can it be implemented?
Edit: To clarify, I am aware that a PDF can contain multiple form fields with different field names, and those can be selected independently, but then the grouping is implicit and not explicit as with the HTML form. I would like to use a construct that makes the grouping of options explicit, and preferably allows for restrictions (e.g. at least one required, no more than 2 allowed, etc).
Edit: If someone can find an authoritative opinion that this is not possible, that would also be a desirable answer.
Yes it is possible. In Adobe PDFs you have the checkbox concept and the radio button concept. While each checkbox and radio button can have its own name, however, they can also be grouped through a subtier via the GroupName.subobj.
Adobe describes it as follows:
The field name. This may include
hierarchical syntax in order to
facilitate logical groupings. For
example, the name myGroup.firstField
implies that the form field firstField
belongs to a group of fields called
myGroup. The advantage of creating
logical hierarchies is that you can
enforce consistency among the
properties of related form fields by
setting the properties of the group,
which automatically propagate to all
form fields within the group.
When the fields are set via a hierarchy you can then get the value of myGroup in this case, and return the selected value of the group. Similarly in the case of RadioButtons you would make sure that all fields in a group have the same name.
This approach to creating form fields
is applicable to all fields, but it
should be noted that radio buttons
require special treatment. Since a set
of radio buttons represents a set of
mutually exclusive choices, they
belong to the same group. Because of
this, the names of all radio buttons
in the same group must be identical.
In addition, the export values of the
set of radio buttons must be set with
a single statement, in which an array
of values are assigned by the
exportValues property of the Field
object. For example, suppose we would
like to create a set of three radio
buttons, each 12 points wide and 12
points high, all named myRadio. We
will place them on page 5 of the
document, and their export values will
be Yes, No, and Cancel. They can be
created as shown in the code given
below:
var name = "myRadio";
var type = "radiobutton";
var page = 5;
var rb = this.addField(name, type, page, [400, 442, 412, 430]);
this.addField(name, type, page, [400, 427, 412, 415]);
this.addField(name, type, page, [400, 412, 412, 400]);
rb.exportValues=["Yes", "No", "Cancel"];
asnyder's response led me to the conclusion that there is no automatic way to handle multiple values within a single field (as one can with HTML). asnyder's examples come from Developing Acrobat Applications Using JavaScript, available from the Acrobat Javascript Developer Center. This document provides some examples of how to manipulate checkboxes, combo boxes, and radio buttons. All of the examples shed some light on the problem and ultimately led me to the conclusion that any system that is using PDF forms will have any multi-selectable groups implicitly defined.
Using the construct of groupName.fieldName appears to be useful to manipulate the widgets as a group (in Acrobat Javascript), but the fields of a group cannot be enumerated (without enumerating all fields and filtering for the groupName), and the collective value of that group cannot be determined without programatically inspecting the values.
In other words, a multi-selectable value is not an intrinsic feature of Acrobat nor of PDF in any substantial way, though it is possible to implement such a form through programming.

Resources