Drupal 8: How do I create a content reference/textarea compound field? - drupal

I have a company content type being used on a website-in-progress. Companies consist of a company name, name sorting mechanism, logo image and URL. I have a requirement to show companies taking part in different use cases in various parts of the website.
Challenge:
In the past I used a company content type for a "corporate members" list on a page, also assigning a "member level" field. But then, companies started being listed as event sponsors with specifics for what they were sponsoring, also with different membership levels in a "corporate giving club". It was messy while added/included in the old company content type. It caused confusion for content editors and developers.
Possible Solution:
In other content types, create compound fields such as "Sponsors", "Corporate members", "Donors", select lists with company entities, or sponsorship detail text areas with company entities. That may keep companies flexible and not messy (keeping company just a company).
Progress:
I found the Double field module, splitting core fields up into two separate parts. This is almost what I'm looking for, providing compound field sets. However, it won't allow references to be selected and is out of the scope of this project per this issue. I'm finding a lot of Drupal 7 examples, but not much Drupal 8 yet.
I'm starting to dig into the examples for developers module for inspiration and will post a solution unless you beat me to it. I'm also open to alternative ideas.
What is the best way to proceed? Specific code examples are not required. I would accept clues that lead me to a final working solution.

The solution turned out to be simpler than creating a custom module.
The Field Collection module allowed for the simple creation of compound fields containing any number and most (if not all) field types, including reference fields. It's also available as a Drupal 8 module (alpha at the time of writing, seems to work fine).

Related

What is the proper way to tag pages in Google Analytics?

I don't even know if "tagging pages" is what I mean.
Essentially, I have a large education website with many types of pages. Specifically, I want to tag our program pages by faculty, level, etc. For example, the Biology program page would be tagged with Science (as its faculty), and Undergraduate (as its level). It's possible that a program could belong to multiple faculties and/or levels (Psychology, for instance, is both a Science program and an Arts program). There is nothing in the URL to signify faculty or level. The website is built in Drupal, in case you know of any modules that could facilitate this.
I want to understand how different faculties/levels/etc perform. I will be building reports in Google Data Studio.
Any guidance would be appreciated!
What you are looking for is called 'content grouping'. If you haven't information in the URL you can define some rules when the page loads and pass the information to Analytics with the pageviews.
You can find more information here:
https://support.google.com/analytics/answer/2853423?hl=en
Then you can get these information from Data Studio.
Because of your multi-value needs, nothing in GA is going to satisfy your requirements out of the box. You will have to do some post-processing, and I am not familiar enough with Data Studio to know where its limits are in that regard.
As the previous poster suggested, Content Grouping is the standard way to create custom aggregations of pages. You can have multiple content groupings, such as Faculty and Level, but a page can be in only one group per grouping (not the clearest terminology but it appears to be what Google uses).
A different option is Custom Dimensions. There are two options here. One is to create custom dimensions for Level and Faculty. Each page can still have only one value per dimension, but you could send a comma-delimited string when a department is in multiple faculties (for instance) and then pull it apart again in a spreadsheet.
The second option is to create a custom dimension for Department directly, and associate each department to the appropriate one or more faculties and levels in your reporting.
How you set the custom dimensions or content grouping will depend on your implementation of GA. If you are using the Google Analytics Drupal module, it says it supports setting custom dimensions as a feature. If you are using Google Tag Manager you can set the dimension value in your tags directly, though of course it will need to decide what value to set on based on either totally enumerated rules you write or something it can read out of the page. Here is some Tag Manager documentation: Content Grouping via GTM; Custom Dimensions via GTM.
If the department is present in the page in some consistently marked-up way you can grab it; if not the Metatag module or one of its schema.org extensions might be able to provide you a spot to set a value for GTM to retrieve.

Custom data plugin

I often deliver wordpress pages because it's easy to setup. When I don't, it's often because the customer need custom data. For example a car dealer would want a data type for car models, car windows and car doors - all with different attributes. These should be editable in the Wordpress admin and also somewhat easy to print out with a foreach loop to the frontend.
I found the plugin Custom Database Tables (https://wordpress.org/plugins/custom-database-tables/) but I would also need relationships between the different tables. If I configure five different car doors, I would want them listed as a select box when I edit a car for example. It doesn't seem to support that?
Is there any alternatives from creating my own plugin for this? Seems like such an ordinary case for non blogs?
Thanks.

Drill Down Search using Sql

it seems like alot of ecommerce sites these days are providing products filters to search for items. For example you can search items by WIDTH,HEIGHT,TV SIZE, Furniture Type etc.
now if it was a simple website with just a few searchable filters then its easy to do, but I am managing a website which sells furniture,appliance & electronics and every category has alot of sub categories as well. for example:
Appliance:
Laundry
Searchable Attributes (Washer,Dryer,Washer Type..Microwave,Width, Height)
Electronics
Tv(Tv Size, Width)
Games (ps3, Genre,Sale Date)
I am sure you get the idea. an ecomerece sites offers basic categoies and then every category could have sub categories OR Searable filters to drill down your search.
what would be the best way to do this using MS SQL Server & Asp.net. I am interested in creating a optimized searchable schema in SQL.
any Hints, Suggestions will be welcome.
Thanks
You can use the Entity-Attribute-Value model.
The simple concept is that instead of having a column for each of your model's attributes (such a genre, sale date, etc for a ps3 game), youll have another table, named Attributes, where the attributes and their types will be listed, and a third table, where your main model instances (ps3 game) will be linked with attributes via 3 columns:
Model Id (the id of the ps3 game)
Attribute Id
Attribute Value
This concept might be harder to manage, and require more complicated queries, but it will alow addition of new products / categorites in the easiest way.
Of course, with this model, if few products share a common attribute (sugh as pc game and ps3 game sharing a genre), you'll have the attribute defined only once, and both model will be linked to it, allowing a common search query on different products.
Too much for a single question. Look for a book on database design. For a drill down you can have a table with as many PK columns as drill downs. But when it comes to details you will need separate tables as TV does not have the same details as a stereo.

drupal user interested terms

hi i'm using drupal 6. In my user page i want to show latest activities related to user interest. interest means terms that user participated (forum topics, articles, polls..). Can any one know the best way to do it.
For ex : stackoverflow shows questions related user participated tags.
This sounds like something you might be able to do using the Flag terms module (http://drupal.org/project/flag_terms). This is a module that complements the much acclaimed Flag module (http://drupal.org/project/flag_terms), by allowing you to flag certain taxonomy terms. You can use views (http://drupal.org/project/views) to display lists of user flagged content.

Categories of tags

I'm starting a pro bono project that is the web interface to the world's largest collection of lute music and it's a challenging collection from several points of view. The pieces are largely from 1400 to 1600, but they range from the mid-1200's to present day. Needless to say, there is tremendous variability in how the pieces are categorized and who they are attributed to. It is obvious that any sort of rigid, DB-enforced hierarchy isn't going to work with this collection, so my thoughts turn to tags.
But not all tags are the same. I'll have tags that represent a person/role (composer, translator, entabulator, etc.), tags that represent the instrument(s) the piece in written for, and tags that represent how the piece has been classified by any one of half a dozen different classification systems used over the centuries.
We will be using a semi-controlled tag vocabulary to prevent runaway tag proliferation (e.g. del.icio.us), but I want to treat the tags as belonging to different groups. People tags should not be offered when the editor is doing instrument tagging, etc.
Has anyone done something like this? I have several ways I can think of to do it, but if there is an existing system that is well-done it would save me time implementing/debugging.
FWIW: This is a Django system and I'm looking at starting with Django-tagging and then hacking from there, possibly adding a category field or ...
There's an issue #14 for django-tagging filed back in 2007 which is trying to address this problem. Don't know whether developers are planning to add this feature or not.
However, there's a machinetags branch of django-tagging mantained by Gregor Müllegger here at https://code.launchpad.net/~gregor-muellegger/django-tagging/machinetags/. It allows to assign tags namespaces (and/or values), and facilitate querying tags by namespace / value. So you'd be able to tag a piece with instrument:<instrument_name> or instrument=<instrument_name>, for example.
It's mostly in sync with the django-tagging trunk (the latest commit is there's a number of commits missing though). I remember myself working on some project using that branch about a year ago; it worked fine. Read the documentation on branch and comments on the issue for more details.

Resources