Closed (fixed)
Project:
Viewfield
Version:
5.x-1.2
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
20 Apr 2007 at 22:21 UTC
Updated:
20 Feb 2008 at 03:12 UTC
Jump to comment: Most recent file
The attached patch allows the admin to specify that only certain views may be selected from a viewfield. That's useful when, for instance you want to create a "table of contents" node type that includes a view, but you will only ever want one view to be included.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | restricted_views_1.patch | 5.76 KB | Crell |
| #4 | restricted_views_0.patch | 4.87 KB | Crell |
| restricted_views.patch | 1.97 KB | Crell |
Comments
Comment #1
mfredrickson commentedI like it. I kept meaning to implement something like this.
One thought: should this be a field or a widget setting? Officially, the CCK "way" is to have the field define it's restrictions. So each viewfield would say which views it accepts.
I don't know that I love that idea. Perhaps we should implement both. The field defines an outer set, and the widget can remove items with that as well.
Thoughts anyone?
Comment #2
yched commentedYeah, the CCK way is that the data definition of the field (which kind of data, which allowsd values...) are field stuff (vs field instance). That's 'only' a convention (sometimes with good technical reasons : it's best to know what you can expect to find in the db columns). But maybe viewfield is an edge case after all...
The 'data' viewfield stores are a view and an 'arguments' string.
What about that :
- Field level : define what views are eligible to use with the field - if only one, then the widget will not display the views selector.
This 'defines' the field. You need another view ? Then you want another field.
- Field instance level :
Using CCK's generic 'default value' handling, you can define a default value for both the view (amongst eligible views) and the arguments (cck's generic default value handling)
Plus viefield_widget_settings defines a checkbox saying 'stick to the default value', and then the widget displays nothing - no views selector, no arguments textfield.
Comment #3
Crell commentedHm. Yeah, it probably would be better on the field rather than the widget. Dur.
I initially had it hide the view selector entirely if only one is selected, but that then hid the field title that said what the arguments are actually for. Does anyone have a suggestion for how to get around that prettily?
@yched: That (viewfield that has a default immutable value) is exactly where I'm headed with this. I left it out at this point because the cck field permissions module can already do that; just set it so that no user (save uid 1) has permissions on that field and it has the same effect.
I probably won't be able to work on this again until Friday afternoon. If someone else wants to pick it up before then and move the code to the field settings rather than widget settings, more power to them. :-)
Comment #4
Crell commentedOK, here we go...
This patch moves the restricted views functionality to the field rather than the widget. it also adds a "force default" checkbox. If that's set, the user will never see the view selector on the edit-node page. It will get auto-assigned to whatever is filled in as the default in the widget. That allows you to have "stealth views" for table of contents pages and the like.
Comment #5
Crell commentedEven better, I just got the special casing of only a single view working. Now it moves the label to the argument field and hides the select box. I also added t() around the "arguments" string and capitalized it appropriately.
Comment #6
marcp commentedThis is a nice patch that will make the DrupalEd Distribution just that much easier to use. We'll be able to remove the caveat here: http://drupaled.alphabetademo.org/?q=wiki/creating-groups by pre-selecting only the views that work within a Course.
I tested out the patch and it works great. Will there be a need for an update_ function in the module to clean up any CCK types that include pre-existing Viewfields?
The only problem with this, in our situation, is that we may add new Views that would work within a Course, so we'll have to update the settings for the fields too. If we had the option of somehow specifying a dynamic subset of Views (either with PHP or a regex or ??? -- in our case, we're using a naming convention for the Views -- they all start with "group_"), we'd be done once the new View was created.
Thanks for this,
Marc
Comment #7
Crell commentedYay, patches that help other projects! :-) A schema update is not necessary, as CCK handles all of that for you. The only thing I can think of is legacy data, but I believe CCK will handle that gracefully. A little bit of testing for that would be great. (I can't; I'm swamped at the moment at work.) If that works without breaking things, please set this RTBC so mfredrickson knows to commit it. Thanks.
Comment #8
mfredrickson commentedCommitted. Thanks to everyone who worked on this.
One small change in the committed version: the "force default" checkbox is now on the widget settings section. Thus, if people want to use other widgets later the "hide all" option is not mandatory. Also, users with 'administer nodes' get the full form on all pages.
Comment #9
mfredrickson commentedComment #10
goose2000 commentedI tried running this patch (restricted_views_1.patch) on the last release viewfield-5.x-1.2.tar.gz
and it started giving errors. The patch was done with patch.exe and no errors were reported.
Any ideas? Dang I need this feature
Comment #11
marcp commentedgoose2000 - This is probably due to legacy data, as Crell mentioned in comment #7. I haven't yet gotten around to reproducing the problem, but I saw some warnings the first time I looked at a previously existing View with a Viewfield in it. I think it got cleared up after saving the View again, though...
Can you reproduce this by rolling your system & data back to the previous version of Viewfield and then updating again?
Comment #12
marcp commentedWhoops, I think I said "View" where I meant "node" a few times in that previous comment... But you probably got the gist of it.
Comment #13
goose2000 commentedHey, I'll be looking at it again today, try to reproduce and document too.
I think were saying 'previously existing NODE with a Viewfield in it'
BTW, is there a patched file you could send, to compare with?
Comment #14
marcp commentedIf you go here: http://cvs.drupal.org/viewcvs/drupal/contributions/modules/viewfield/vie...
You can probably try the latest version that Mark has checked in...
Comment #15
goose2000 commentedWow, a hidden 'force view' and tokens too, cool. Were there any DB changes? Like to hold the 'force view' or other default options? I did download the latest from cvs and looks to work, but won't save my 'force view' check box. ?
Ohhh this will be neat.
Comment #16
goose2000 commentedHi, I've been testing this version:
viewfield.module,v 1.3.2.8 2007/05/29 02:50:49
I get no errors, and seems right except, when I choose the force mode:
Force default
If checked, the user will not be able to change anything about the view at all. It will not even be shown on the edit node page. The default value will be used instead.
The setting does not save. Is there some DB change to hold this info? All other settings for the field save fine.
Comment #17
(not verified) commentedComment #18
chewblocka commentedAny idea when there will be a new release to include this feature? It would be VERY useful to me but I'm not too keen on switching to the HEAD. Even a 5.x-1.3-dev semi-stable release would be better than HEAD.
Comment #19
leanazulyoro commentedhi, i'm getting this errors:
# warning: array_flip() [function.array-flip]: The argument should be an array in ..\modules\cck\viewfield\viewfield.module on line 216.
# warning: in_array() [function.in-array]: Wrong datatype for second argument in ..\all\modules\cck\viewfield\viewfield.module on line 219.
line 216: $allowed_views = array_flip($field['widget']['allowed_views']);
line 219: if (! (0 === $key || in_array($key, $allowed_views))) {
this warnings appear when creating the field, and in the manage fields page when a view field is listed.
the patch works ok eventhough i get this warnings. i have one warning as the first descrved and LOTS of the second descrived. any idea?
my viewfield version: 5.x-1.2