1 of 4
1
Gypsy
Posted: 17 December 2008 02:42 PM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  279
Joined  01-02-2008

A few days ago, slapshotw and I were discussing / collaboratively venting about the way EE handles custom fields + field groups + weblogs. There’s a lot of repetition involved: It’s not rare for a site to have the same field duplicated throughout multiple field groups, and multiple near-identical field groups thanks to little differences.

But those days are gone now, with a little help from my new extension, Gypsy!

In a nutshell, Gypsy frees your custom fields from their field groups, enabling you to assign them directly to your weblogs.


Get it now! brandon-kelly.com/apps/gypsy


Usage
You can turn any of your custom fields into “gypsies” from the Edit Custom Field page. Find the preference labelled “Is this a gypsy field?” and set it to Yes. Then choose which weblogs you want your field to appear in from the multi-select box that appears below.


Enjoy!

Image Attachments
gypsy.jpg
Click thumbnail to see full-size image
 Signature 

brandon-kelly.com    @brandonkelly

Profile
 
 
Posted: 17 December 2008 03:02 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  279
Joined  06-24-2007

I feel like I just took some LSD.  This is so OUT THERE!  Zany!

 Signature 

Chad Crowell | Encaffeinated, Inc. | Formerly Web Inception | @chadcrowell | @encaffeinated

Profile
 
 
Posted: 17 December 2008 03:07 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  844
Joined  10-14-2005

So in theory you could create a single custom field group and then add a ton of custom fields which are ‘gypsies’ and then assign them to the relevant weblogs, negating the need for multiple custom field groups at all?

If so sounds like a really powerful extension and I can’t wait to give it a shot! smile

 Signature 

Nathan Pitman - Nine Four

Follow me on Twitter - Try my EE plug-ins and extensions

Profile
 
 
Posted: 17 December 2008 03:08 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2122
Joined  03-26-2006

I played with the beta for a bit yesterday (thanks for that!) and was pretty impressed.

I will have to test this a bit to see about best way to implement. Right now you can do one of two things: make a Gypsy field in a particular weblog’s custom field group and share it with other weblogs, or make a dedicated “Gypsy” custom field group that isn’t assigned to any weblog, and store all your Gypsy fields there (like Nathan just said above…he posted as I was writing this).

Only other thing to watch out for is the field order. If your gypsy field is “100” - that may show up first in one weblog Pub/Edit page, or 10th in another. If you are as anal as I am about what order your fields are in, you will have to adjust non-gypsy fields flow around them.

Much needed extension. Great work!

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 17 December 2008 03:11 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  279
Joined  01-02-2008

Quick note—I have not tested this with PHP4. I suspect it will work just fine, but if you have PHP4 please verify!

 Signature 

brandon-kelly.com    @brandonkelly

Profile
 
 
Posted: 17 December 2008 03:11 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  844
Joined  10-14-2005

I guess the only solution to that would be to somehow introduce a set of secondary entry fields which allowed you to set the order of that gypsy field relative to each assigned weblog… could get messy but I’m sure Brandon would come up with a simple but brilliantly clever solution. smile

 Signature 

Nathan Pitman - Nine Four

Follow me on Twitter - Try my EE plug-ins and extensions

Profile
 
 
Posted: 17 December 2008 03:17 PM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  279
Joined  01-02-2008
Nathan Pitman (Nine Four) - 17 December 2008 03:11 PM

I guess the only solution to that would be to somehow introduce a set of secondary entry fields which allowed you to set the order of that gypsy field relative to each assigned weblog… could get messy but I’m sure Brandon would come up with a simple but brilliantly clever solution. smile

My current stance on field order is: it works as-is. If you set a Gypsy field to order #100, you can then edit your other fields’ order #s to work around the Gypsy field.

 Signature 

brandon-kelly.com    @brandonkelly

Profile
 
 
Posted: 17 December 2008 03:24 PM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  844
Joined  10-14-2005

...and in reality how often is an admin likely to fiddle with field order once the initial site setup is done… so yes there’s really no need for a complicated solution. smile

 Signature 

Nathan Pitman - Nine Four

Follow me on Twitter - Try my EE plug-ins and extensions

Profile
 
 
Posted: 17 December 2008 03:59 PM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2122
Joined  03-26-2006

Another way to have approached this would have been to allow a weblog to have multiple field groups, but this is ultimately more flexible.

 Signature 

ryan masuga
—————
Masuga Design (EE Pro) | devot:ee
MD Markitup | All Add-Ons
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 17 December 2008 04:08 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  279
Joined  01-02-2008
mdesign - 17 December 2008 03:59 PM

Another way to have approached this would have been to allow a weblog to have multiple field groups, but this is ultimately more flexible.

For sure. I considered at least three different approaches to Gypsy, but settled on this because it had the best flexibility-to-difficulty ratio.

 Signature 

brandon-kelly.com    @brandonkelly

Profile
 
 
Posted: 17 December 2008 04:15 PM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1306
Joined  01-24-2006

Wow… this looks sweet. Good work Brandon! Can’t wait to try it out

 Signature 

Newism - Newcastle Web Design & Development


NSM Publish Plus - Collaborative workflow and live entry previews
LG Better Meta - SEO Meta & XML Sitemap Generator
LG Polls
LG .htaccess Generator
20+ EE addons

Profile
 
 
Posted: 17 December 2008 04:17 PM   [ Ignore ]   [ # 11 ]  
Grad Student
Avatar
Rank
Total Posts:  89
Joined  04-30-2007

Lots of familiar commenters on this thread thus far. Hello fellow Twitterers smile Absolutely fantastic idea Brandon. Can’t wait to try this out.

 Signature 

Casey Reid // Clear Fire Studios // EE Pro Network // @caseyreid

Profile
 
 
Posted: 17 December 2008 04:40 PM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1658
Joined  05-15-2004

This sounds great. smile

I don’t suppose its possible to extend it with some kind of migration utility for existing sites that already have fields repeated over several custom field groups?

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 17 December 2008 06:06 PM   [ Ignore ]   [ # 13 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  279
Joined  01-02-2008
Linda A - 17 December 2008 04:40 PM

I don’t suppose its possible to extend it with some kind of migration utility for existing sites that already have fields repeated over several custom field groups?

Here’s a little script I just wrote that will copy all of your field data from one field to another:

<?php


// -------------------
//  Configuration
// -------------------


// Old Field Names
$old_fields = array(
    
'old_field_1',
    
'old_field_2',
    
'old_field_3'
    
// etc.
);

// Gypsy Field Name
$gypsy_field = 'gypsy_field';

// Database Server
$db_server = 'localhost';

// Database User Name
$db_username = 'username';

// Database User Password
$db_password = 'password';

// Database Name
$db_name = 'my_website';


// -------------------
//  Script
// -------------------


// Connect to the database
$db_link = mysql_connect($db_server, $db_username, $db_password)
    OR exit(
'Could not connect to MySQL.');
mysql_select_db($db_name, $db_link)
    OR exit(
'Could not connect to the database.');

// Get the Gypsy field's ID
$gypsy_field_result = mysql_query("SELECT field_id
                                   FROM exp_weblog_fields
                                   WHERE field_name = '{$gypsy_field}'"
, $db_link) OR exit(mysql_error());
if ( !
mysql_num_rows($gypsy_field_result))
    exit(
"No field exists with the name \"{$gypsy_field}\"");
$gypsy_field_id = 'field_id_'.mysql_result($gypsy_field_result, 0);

// Get the old fields' IDs
$old_fields_result = mysql_query("SELECT field_id
                                  FROM exp_weblog_fields
                                  WHERE field_name IN ('"
.implode(',', $old_fields)."')", $db_link) OR exit(mysql_error());
if ( !
mysql_num_rows($old_fields_result))
    exit(
'No fields exist with the names "'.implode('", "', $old_fields).'"');

// Update Gypsy field's data with content from each old field
while($row = mysql_fetch_row($old_fields_result)) {
    $old_field_id
= "field_id_{$row[0]}";
    if (
$old_field_id == $gypsy_field_id)
        continue;
    
    
$data_result = mysql_query("SELECT entry_id, {$old_field_id} data
                                FROM exp_weblog_data
                                WHERE {$old_field_id} != ''"
, $db_link) OR exit(mysql_error());
    if ( !
mysql_num_rows($data_result))
        continue;
    while(
$data_row = mysql_fetch_assoc($data_result)) {
        mysql_query
("UPDATE exp_weblog_data
                     SET {$gypsy_field_id} = '"
.addslashes($data_row['data'])."'
                     WHERE entry_id = '{$data_row['entry_id']}'"
, $db_link) OR exit(mysql_error());
    
}
}

echo "Success!";

?>

First go into your CP and create your new gypsy field. Then save that script as a PHP file, change the Configuration variables at the top, upload it to your website, and access it from your browser. (And when you’re done migrating, delete the old fields AND DELETE THAT SCRIPT!)

 Signature 

brandon-kelly.com    @brandonkelly

Profile
 
 
Posted: 17 December 2008 06:08 PM   [ Ignore ]   [ # 14 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1658
Joined  05-15-2004

Oh, wow, fabulous. Thank you so much. smile

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 18 December 2008 05:03 AM   [ Ignore ]   [ # 15 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  10765
Joined  04-15-2006
Casey Reid - 17 December 2008 04:17 PM

Lots of familiar commenters on this thread thus far. Hello fellow Twitterers smile Absolutely fantastic idea Brandon. Can’t wait to try this out.

Hiya Casey.

Just come in to post after I Twittered about this last night and I see this is already getting the exposure it so rightly deserves. This really really needs to be in ExpressionEngine as standard. I’ve only used this exceptionally quickly but it is absolutely fantastic, well done Brad.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin
Full list of add-ons
———————————————————-
Buy me a drink, or two if you like!!

Profile
 
 
Posted: 18 December 2008 07:31 AM   [ Ignore ]   [ # 16 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2041
Joined  09-16-2004

Awesome this, will definitely try this out in a next project. Many thanks!

 Signature 

Peace, e-man.
stookstudio.com, websites built with care and web standards. LinkedIn profile

Profile
 
 
Posted: 18 December 2008 10:53 PM   [ Ignore ]   [ # 17 ]  
Lab Assistant
RankRank
Total Posts:  117
Joined  09-19-2006

This just solved several serious headaches for me - title fields for multilingual sites for one…

Brilliant work Brandon!

-Brent

Profile
 
 
Posted: 19 December 2008 05:14 PM   [ Ignore ]   [ # 18 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  307
Joined  03-04-2008

This does sound like a really excellent extension and one I am bound to use in the future. Good work Brandon!

 Signature 

Richard Angstmann
Web Design | Websites | Online Shops | Spennymoor | Durham

Profile
 
 
   
1 of 4
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120007 Total Logged-in Users: 97
Total Topics: 126139 Total Anonymous Users: 73
Total Replies: 663537 Total Guests: 469
Total Posts: 789676    
Members ( View Memberlist )