| Project: | Domain Access |
| Version: | 6.x-2.0-rc5 |
| Component: | Miscellaneous |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
| Issue tags: | Content type, subdomains |
Issue Summary
I searched for an answer, but I couldn't find anything. Could anybody please point me in the right direction?
I am doing a clean install of drupal for and Domain Access with several subdomains, such as:
maindomain.com
subdomain1.maindomain.com
subdomain2.maindomain.com
subdomain3.maindomain.com
The different subdomains will have different custom content types. Say, subdomain1 will have ONLY news content type, subdomain2 will have ONLY article content type, and so on. I will have editors who are assigned permissions to post/edit content for one o multiple subdomains. My problem is that I don't want a certain content type to be publishable to other domains except the one it is assigned to.
My question is: is it possible to restrict the posting of a certain content type to a certain domain using Domain Access? That is, for editor X to be able to post a news content type ONLY to subdomain1.maindomain.com from any of the domains?
Thanks.
Comments
#1
Not without custom code.
#2
If it's not possible now, I think this would be a good feature to have. Restricting a certain content type to a certain domain.
#3
Similar to liternet's request, I need to control the showing of cck fields based on which domain the node is being shown in.
To explain, assume the following:
- a drupal site uses the Domain Access module and has two domains: d1 and d2
- a content type is created that has 3 cck fields: F1, F2, F3
When a node is shown in domain d1 the node should show cck fields F1 and F3, however when a node is shown in domain d2 the node should show cck fields F2 and F3
Perhaps there is, or will be a way to do this without using Views or programming?
Jerry
#4
No, you have to use hook_form_alter() or a similar mechanism in both cases.
#5
How do you manipulate DA from within hook_form_alter()? I tried dumping the $form array and I could not find anything in there relating to DA. So, I'm at a loss as to how to access and alter DA functionality.
#6
Maybe you should create table prefix for users.
#7
subscribing. I too am looking to restrict content per domain.
#8
We are very insteresting by this feature.
In our case, all sites share the sames contents types (for example, ContentType1, ContentType2, ContentType3, ContentType4), but we want restrict access ContentType4 to all user with "Edit domain node" permission.
#9
Has anyone developed a workaround for this?
#10
You can do this by developing roles for different users. So that there is a "SiteA roles" and they are the only ones that can create/edit/delete news contents. You then set "SiteA" users to have a default domain of "SiteA".
This is doable, you just have to have a very strategic approach in the setup of:
-Views
-Domain Access
-Taxonomy Access Control
-User Roles
We are doing something very similar to what you are referring to. There are some overlap in what content can go where, but it is very doable.
In views you need to make heavy use of the domains filtering option
in the DA you need to have it configured to use your DA editors, etc
We use TAC so that certain groups only see certain parts of our tax tree
User Roles are the most meticulous setup of them all. It took a bit of testing to get them straightened out.
I also developed a module that automated the assignment of default domain publishing. So that it reads user's credentials and then assigns them to particular domains that I allow them to.
#11
I would swear that someone released a module for this, or at least posted one in the queue. Search around and see if you can find it.
#12
you could use:
http://drupalmodules.com/module/content-access
This module lets you set rules for who can post what content. Then let DA handle where they are allowed to post that content. Though if userA is part of siteA and siteB then your still back to square 1.
#13
Same situation for us. User A is part of both sites... and trying to restrict content types per site.
#14
@jkdrupal: did you resolve your issue finally? How?
Thank you
#15
@MXT, We have not fully solved the problem I described. What we decided to do until we find something better is a subset of what lilott8 described in post #10. We cannot control access in the way we would prefer, but it is the best we can do for now.
#16
Subscribing. Sames needs here, and interested to know whenever a configuration, module combination, or DA feature (D7?) comes up.
#17
In D7, this is almost trivial. In D6, you can do it with a form_alter() or a menu_alter().
#18
For those that are newer to development (like me) and are unsure how to begin doing something like this. Here is a quick and easy way to restrict a content type from being created or assigned to a particular domain. I hope to eventually flush this out into a module with an administrative interface so this doesn't have to be done just in code.
Restricting a content type from being created while in a domain
In order to restrict a content type from being added we have to use a hook_menu_alter to change the permission based on the domain the user is in. In this example I am making it so that the "story" content type can't be added for a certain domain.
function mymodule_menu_alter(&$items) {$items["node/add/story"]['access callback'] = 'mymodule_domain_check';
$items["node/add/story"]['access arguments'] = array('story');
}
Next we create the mymodule_domain_check function
function mymodule_domain_check($content_type) {
global $_domain;
$id = $_domain['domain_id'];
if (user_access("create $content_type content")) { // Checks if the user has permission to create the content type in the first place
if ($content_type == "story" && $id == 1) { // replace with the id of the domain you wish to exclude
return FALSE;
}
return TRUE;
} else {
return FALSE;
}
}
Be sure to flush your menu cache when making changes to hook_menu_alter!
The basic idea is that I check if the user has access to the add a story, if they do then we check which domain they are in, if it's a domain we don't want them to create stories in we return false, otherwise we can return true. The ID value of a domain can be determined by looking at the url of the domain edit links on the domain configuration pages.
So now if a user is on domain 1 and tries to add a story they will get an access denied, but on other domains they will be able to add them no problem. This method will even remove the content type from the /node/add page and any other menu items that refer to /node/add/story for that domain.
Removing the domain in the affiliate publishing options for a content type
We have already prevented a user from adding stories on the domain of our choice, but if a user can publish to more than one domain we also want to remove that domain from the publishing options of that content type. To do so we need to perform a hook_form_alter.
function mymodule_form_alter(&$form, &$form_state, $form_id) {if ($form['type']['#value'] == 'story') {
unset($form['domain']['domains']['#options'][1]);
}
}
Here we unset the option in the node add/edit form to remove the domain 1 for the story content type. So that users can't publish the story content type on domain 1. You may need to use dsm or print_r on the $form object to see exactly which #options item you want to remove.
So this is how I've used hook_form_alter and hook_menu_alter to not allow content types on certain domains. The only situation this doesn't address is if a user has access to the "send to all affiliates" checkbox. But I have disabled that on my sites as I don't think it's an option that many people should have.
Hope this is helpful to others.
#19
Thank you! Subscribing. If you turn this into a contributed module please consider supporting multiple domains (i.e.: restrict a content type from being created or assigned to particular domains)
#20
Subscribe
#21
I rolled arvinsingla's solution from 18 into the attached module.
arvinsingla do you want to start a project page for this?
[edit]
This module provides an administrative interface for multiple domains.
#22
Thank you arvinsingla and jbomb! I just tried it and it works nicely. Could the restriction be configured also for domain 0? I see it configurable for alfa.domain.com and beta.domain.com etc... but not for domain.com (id 0 in my case)
[edit] also, how would I go about a domain where I should not publish ANY content? As it is now I have to allow at least one...
#23
Skizzo:
You can apply the restriction to the primary domain by removing the "if" directive at line 76 of domain_content_types.module so that the function just returns the $links array. I'm not sure what is preventing you from restricting content from all domains.
[edit]
OH! I see what you mean... We will have to add an option to exclude all content types.
#24
skizzo: The following adds the ability to exclude all content types and fixes a few other small bugs I encountered. This should probably be moved to a project page to track issues.
#25
There's now a project page for Domain Content Types from #18 and #24.
#26