<commit_before><?php

class dmTagPluginConfiguration extends sfPluginConfiguration
{
  public function configure()
  {
    $this->dispatcher->connect('dm.context.loaded', array($this,'listenToDmContextLoaded'));
  }

  public function listenToDmContextLoaded(sfEvent $e)
  {
    $cache = $e->getSubject()->get('cache_manager')->getCache('dm_tag');

    $taggableModels = $this->getTaggableModels($cache);

    $taggableModels = $this->dispatcher->filter(new sfEvent(
      $this, 'dm_tag.taggable_models.filter', array()
    ), $taggableModels)->getReturnValue();

    foreach($this->getTaggableModels($cache) as $model)
    {
      dmDb::table($model);
    }

    if($this->configuration instanceof dmAdminApplicationConfiguration)
    {
      $this->dispatcher->connect('form.post_configure', array($this, 'listenToFormPostConfigureEvent'));
    }

    $this->dispatcher->connect('dm.admin_generator_builder.config', array($this, 'listenToAdminGeneratorBuilderConfig'));

    $this->dispatcher->connect('dm.table.filter_seo_columns', array($this, 'listenToTableFilterSeoColumns'));
  }

  public function listenToAdminGeneratorBuilderConfig(sfEvent $event, array $config)
  {
    if($event['module']->getTable()->hasTemplate('DmTaggable'))
    {
      foreach($config['form']['display'] as $fieldset => $fields)
      {
        if(false !== ($tagsListPosition = array_search('tags_list', $fields)))
        {
          $config['form']['display'][$fieldset][$tagsListPosition] = 'tags';
        }
      }
    }

    return $config;
  }

  public function listenToTableFilterSeoColumns(sfEvent $event, array $seoColumns)
  {
    if($event->getSubject()->hasTemplate('DmTaggable'))
    {
      $seoColumns[] = 'tags_string';
    }

    return $seoColumns;
  }

  public function listenToFormPostConfigureEvent(sfEvent $event)
  {
    $form = $event->getSubject();

    if($form instanceof dmFormDoctrine && $form->getObject()->getTable()->hasTemplate('DmTaggable'))
    {
      $form->setWidget('tags', new sfWidgetFormDmTagsAutocomplete(
        array('choices' => $form->getObject()->getTagNames())
      ));

      $form->setValidator('tags', new sfValidatorDmTagsAutocomplete());<commit_msg>made tags not required in forms<commit_after><?php

class dmTagPluginConfiguration extends sfPluginConfiguration
{
  public function configure()
  {
    $this->dispatcher->connect('dm.context.loaded', array($this,'listenToDmContextLoaded'));
  }

  public function listenToDmContextLoaded(sfEvent $e)
  {
    $cache = $e->getSubject()->get('cache_manager')->getCache('dm_tag');

    $taggableModels = $this->getTaggableModels($cache);

    $taggableModels = $this->dispatcher->filter(new sfEvent(
      $this, 'dm_tag.taggable_models.filter', array()
    ), $taggableModels)->getReturnValue();

    foreach($this->getTaggableModels($cache) as $model)
    {
      dmDb::table($model);
    }

    if($this->configuration instanceof dmAdminApplicationConfiguration)
    {
      $this->dispatcher->connect('form.post_configure', array($this, 'listenToFormPostConfigureEvent'));
    }

    $this->dispatcher->connect('dm.admin_generator_builder.config', array($this, 'listenToAdminGeneratorBuilderConfig'));

    $this->dispatcher->connect('dm.table.filter_seo_columns', array($this, 'listenToTableFilterSeoColumns'));
  }

  public function listenToAdminGeneratorBuilderConfig(sfEvent $event, array $config)
  {
    if($event['module']->getTable()->hasTemplate('DmTaggable'))
    {
      foreach($config['form']['display'] as $fieldset => $fields)
      {
        if(false !== ($tagsListPosition = array_search('tags_list', $fields)))
        {
          $config['form']['display'][$fieldset][$tagsListPosition] = 'tags';
        }
      }
    }

    return $config;
  }

  public function listenToTableFilterSeoColumns(sfEvent $event, array $seoColumns)
  {
    if($event->getSubject()->hasTemplate('DmTaggable'))
    {
      $seoColumns[] = 'tags_string';
    }

    return $seoColumns;
  }

  public function listenToFormPostConfigureEvent(sfEvent $event)
  {
    $form = $event->getSubject();

    if($form instanceof dmFormDoctrine && $form->getObject()->getTable()->hasTemplate('DmTaggable'))
    {
      $form->setWidget('tags', new sfWidgetFormDmTagsAutocomplete(
        array('choices' => $form->getObject()->getTagNames())
      ));

      $form->setValidator('tags', new sfValidatorDmTagsAutocomplete(array(
        'required' => false
      )));
{'fraction_non_alphanumeric': 0.1596223021582734, 'fraction_numerical': 0.0, 'mean_word_length': 4.360240963855421, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1775827', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1331, 'n_words': 184}