1
votes

I have two models in my Symfony application. First one is Blog:

Blog:
  columns:
    name: { type: string(20), notnull: true, unique: true }
    title: { type: string(255), notnull: true }
    description: { type: string(255), notnull: true }
    admin_id: { type: bigint, notnull: true }
  relations:
    User:
      class: sfGuardUser
      local: admin_id
      ...

As you can see this model has a one-to-one relationship with sfGuardUser. I want the registration of these two take place in one form.

So I changed the BlogForm class and used embeddedRelation method in it. So two forms just appear together. The problem is their view! User registration form (which is embedded in BlogForm) seems like child! I don't want this... I want the fields be at the same indent.

My form view is like this:

My Current View

But I want something like this:

enter image description here

What is the best way to do this? Does it relate to FormFormatter?

1

1 Answers

1
votes

Have you check sfWidgetFormSchemaFormatter or render* method ?

I gave an answer for something almost related here. And I think it's almost the same problem that came here: Removing table headers from embedRelation()

I think the best way is to manually build the form in the template using sfWidgetFormSchemaFormatter or render* method.


Edit:

Regarding what I've answered here, try to add a custom formatter like this (in lib/widget/sfWidgetFormSchemaFormatterAc2009.class.php) :

class sfWidgetFormSchemaFormatterAc2009 extends sfWidgetFormSchemaFormatter
{
  protected
    // this will remove table around the embed element
    $decoratorFormat = "%content%";

  public function generateLabel($name, $attributes = array())
  {
    $labelName = $this->generateLabelName($name);

    if (false === $labelName)
    {
      return '';
    }

    // widget name are usually in lower case. Only embed form have the first character in upper case
    if (preg_match('/^[A-Z]/', $name))
    {
      // do not display label
      return ;
    }
    else
    {
      return $this->widgetSchema->renderContentTag('label', $labelName, $attributes);
    }
  }
}

Then add it to your form in ProjectConfiguration:

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    // ...

    sfWidgetFormSchema::setDefaultFormFormatterName('ac2009');
  }
}

(information comes from sf website)

If this doesn't work, please add a var_dump($name); before the if (preg_match and add the output to your question.