Let's add a domain reference field type, so that we can at least link all types of entities with domains. In the future we might be able to use this field to also do logic, but to start out with, it should just be a simple field, and not use any logic.

Comments

dave reid’s picture

I'm guessing that this should probably store machine names rather than domain IDs as well considering the exportability of domains.

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new7.24 KB

Here's what the initial code looks like. Seems to be working quite well already.

Screenshots:
http://i.imgur.com/GHLEP.png (single value field using the select widget)
http://i.imgur.com/JHadZ.png (multiple value field using the checkboxes widget)
http://i.imgur.com/cZX4N.png (field settings)

dave reid’s picture

StatusFileSize
new10.55 KB

Made a domain_get_domain_options() function re-usable for FAPI #options of domains.

dave reid’s picture

StatusFileSize
new13.44 KB

Added a 'tokenized link or text' formatter that allows for more customization of the field output as well.

dave reid’s picture

Marked #1587468: Show source's site name and not use redirect as a duplicate of this issue.

agentrickard’s picture

Status: Needs review » Needs work

Fatal typo:

+    $options = domain_get_domain_options(array('sanitize' => emtpy($format)));
dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new13.44 KB

Whoops!

alan d.’s picture

Nice approach.

I'm' not sure if I like the decoupled domain idea or not for tracking strict domain info, as there is a lot of additional logic that goes with it, like ensuring that the selected domain is part of the $entity->domains array, etc. In response to #1587468: Show source's site name and not use redirect, I actually wrote an entity based clone of domain source, but without the redirect. Ping me if anyone wants the code for this.

colle901’s picture

I like the idea of domain reference fields, and the patch works good for me.

However, I need to apply a filter in Views to restrict the domain reference field to the current domain. The Domain Views module provides a contextual filter for the current domain, but it returns the domain id instead of the machine name. Should this mismatch be dealt with as part of this issue, or should the topic be raised in the Domain Views module issue queue?

agentrickard’s picture

I think someone already opened a similar issue in Domain Views. Check there. If not, open a new issue that points to this one.

agentrickard’s picture

agentrickard’s picture

Status: Needs review » Needs work

I just re-read this patch and here are some notes:

1) It likely won't apply after other recent commits. So that needs checking.

2) It touches other functions needlessly. And, in the case of domain_machine_name_load(), breaks the function signature.

3) domain_get_domain_options() is undocumented.

agentrickard’s picture

dave reid’s picture

The two issues are pretty independent.

stealthtech1’s picture

Thank you this is what i need. But i am wondering why you use the machine name as the stored value and not the domain id? The machine names can change but the id does not

agentrickard’s picture

@stealthtech1

In a configuration / migration scenario that is actually reversed. Machine names are considered more stable.

nicksanta’s picture

StatusFileSize
new10.74 KB

Patch attached is adapted from Dave Reid's in #7, with agentrickard's feedback from #12.

Note that I have not documented domain_get_domain_options() properly. Applies properly against 7.x-3.x branch as of this morning.

nicksanta’s picture

Status: Needs work » Needs review
kingandy’s picture

Seems to commit fine against 7.x-3.4 too :D

kingandy’s picture

Still commits against 7.x-3.10, though it doesn't integrate with Views filters very well - it's giving me a text entry field instead of a list of domains...

valentin schmid’s picture

Issue summary: View changes

Patch 17 works also flawlessly with 7.x-3.11.
Is there any chance for this patch to become integrated in the Domain Access module?
Or should this functionality be implemented in a separate module?

rich.3po’s picture

StatusFileSize
new10.74 KB

Thanks for the v useful patch - also just applied to 7.x-3.11 with no problems... Except:

There is a small bug in the domain_get_domain_options() function. The line:

if (!empty($options['valid']) && empty($data['valid']) && !user_access('access inactive domains')) {
should be
if (!empty($options['valid']) && empty($domain['valid']) && !user_access('access inactive domains')) {

(the $data variable does not exist - presumably a typo)

Fixed patch attached

vadim_k’s picture

Thanks for this patch. Works greatly with 7.x-3.11.
Please tell me how can I exclude the main domain from list in the field?

jsacksick’s picture

Is it going to be committed someday? The first patch has been sent two years ago. I need this functionality, domain_entity in contrib is doing the job but it doesn't store the machine name which is problematic as explained in #16.

This module is also adding some logic on top by implemeting the hook_query_alter().
So i'm wondering what to do? Open a new branch in domain_entity, create my own module or use this patch and add my logic on top to hide the entities?

As for #20? it's not exposed to views because it's not exposed to Entity API, in order to do that, the property_callbacks information needs to be declared, See https://www.drupal.org/node/1156554

jsacksick’s picture

For those who need this functionality and don't want to maintain a patch, I created a sandbox https://www.drupal.org/sandbox/jsacksick/2315845

vadim_k’s picture

@jsacksick
can you also include autocomplete field type? it will be very useful I think

jsacksick’s picture

@vadim_k Any feature request should now be created in the issue queue of the sandbox. Feel free to provide a patch.

rich.3po’s picture

With regards to domain_entity which was mentioned above...
https://www.drupal.org/project/domain_entity

Is this ticket just reproducing what has probably been done by that module, the latter with richer functionality?

jweirather’s picture

Is this related? https://www.drupal.org/sandbox/mathieso/1728466.

Either way, should that sandbox page include a reference back here?

joachim’s picture

In response to #28:

The domain_entity field appears to store numeric IDs, which is not ideal. Also, while I've not investigated enough to be sure, I'm guessing that domain_entity's field type is used only to assign a domain to an entity for purposes of access. There are other use cases where you want to create a connection between an entity and a domain.

bluegeek9’s picture

Status: Needs review » Closed (outdated)

Drupal 7 in End of Life and no longer supported. We encourage you to upgrade to a supported version of Drupal. For more information, see https://www.drupal.org/upgrade.

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support of this project makes other volunteer contributions more sustainable.
There are multiple ways to show appreciation for the work contributed to this project, including:
  • Triaging issues and adding more context to existing issues.
  • Writing documentation or patches for this project.