google-code-export / wordpress-custom-content-type-manager

Automatically exported from code.google.com/p/wordpress-custom-content-type-manager
2 stars 1 forks source link

Architecture Improvement: add "get_selected_posts" filter to CCTM_FieldElement class #496

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
For the RelationMeta fields, it'd be better if the code from the 
ajax-controller/get_selected_posts.php were put into the relationmeta.php class:

if ($def['type']=='relationmeta') {

        $r['metafields'] = '';

        // Custom fields        
        $custom_fields = CCTM::get_value($def, 'metafields', array());
        $relationmeta_tpl = CCTM::load_tpl(
            array('fields/options/'.$def['name'].'.tpl'
                , 'fields/options/_relationmeta.tpl'
            )
        );      
        foreach ( $custom_fields as $cf ) {
            // skip the field if it no longer exists
            if (!isset(CCTM::$data['custom_field_defs'][$cf])) {
                continue;
            }
            $d = CCTM::$data['custom_field_defs'][$cf];
            if (isset($d['required']) && $d['required'] == 1) {
                $d['label'] = $d['label'] . '*'; // Add asterisk
            }

            $output_this_field = '';
            if (!$FieldObj = CCTM::load_object($d['type'],'fields')) {
                continue;
            }

            $d['name'] = $fieldname.'['.$r['ID'].']['.$d['name'].']';
            $d['is_repeatable'] = false; // override
            $FieldObj->set_props($d);
            $output_this_field = $FieldObj->get_create_field_instance();
            $r['metafields'] .= CCTM::parse($relationmeta_tpl, array('content'=>$output_this_field));
        }
}

That chunk of code is more or less duplicated inside the relationmeta.php's 
get_edit_field_instance() function.  Code duplication is bad...

Original issue reported on code.google.com by ever...@fireproofsocks.com on 15 May 2013 at 4:45