PageRenderTime 30ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/dmAdminPlugin/data/generator/dmAdminDoctrineModule/dmAdmin/template/templates/_form_field.php

http://github.com/diem-project/diem
PHP | 171 lines | 154 code | 16 blank | 1 comment | 26 complexity | 93f64759c283039440ddda937d8dd507 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT, ISC
  1. [?php
  2. $required = ($validator = $form->getValidatorSchema()->offsetGet($name)) ? $validator->getOption('required') : false;
  3. // embedded media forms are required if their file field is required
  4. $required && $form[$name] instanceof sfFormFieldSchema && ($formValidator = $form->getValidatorSchema()->offsetGet($name)) && $formValidator instanceof sfValidatorSchema && ($fileValidator = $formValidator->offsetGet('file')) && $required = $fileValidator->getOption('required');
  5. $divClass = dmArray::toHtmlCssClasses(array(
  6. $class,
  7. ($field->getConfig('is_big') || $field->getConfig('markdown')) ? 'big' : '',
  8. $field->getConfig('is_link') ? 'dm_link_droppable' : '',
  9. $required ? 'required' : ''
  10. ));
  11. if('empty_' === $name)
  12. {
  13. echo '<div class="'.$divClass.'"></div>';
  14. return;
  15. }
  16. if(empty($label))
  17. {
  18. $label = dmString::humanize($name);
  19. }
  20. $label = __($label, array(), '<?php echo $this->getModule()->getOption('i18n_catalogue')?>');
  21. if($form->getObject()->getTable()->isI18nColumn($name))
  22. {
  23. $flag = $sf_user->getCulture();
  24. if(strlen($flag) > 2) {
  25. $flagPath = sfConfig::get('dm_core_dir').DIRECTORY_SEPARATOR.'web'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'flag-16';
  26. if(file_exists($flagPath.DIRECTORY_SEPARATOR.strtolower(substr($flag, strpos($flag, '_')+1)).'.png')) {
  27. $flag = strtolower(substr($flag, strpos($flag, '_')+1));
  28. } elseif(file_exists($flagPath.DIRECTORY_SEPARATOR.strtolower(substr($flag, 0, 2)).'.png')) {
  29. $flag = substr($flag, 0, 2);
  30. }
  31. }
  32. $label = _media('dmCore/images/flag-16/'.$flag.'.png')
  33. ->size(16, 11)
  34. ->set('.dm_label_culture')
  35. ->alt(format_language($sf_user->getCulture())).
  36. $label;
  37. }
  38. if($required)
  39. {
  40. $label = $label.
  41. _media('dmCore/images/16/required.png')
  42. ->size(16, 16)
  43. ->set('.dm_label_required')
  44. ->alt(__('Required.', array(), 'sf_admin'));
  45. }
  46. ?]
  47. [?php if ($field->isPartial()): ?]
  48. <div class="[?php echo $divClass ?]">[?php include_partial('<?php echo $this->getModuleName() ?>/'.$name, array('<?php echo $this->getModule()->getKey() ?>' => $form->getObject(), 'form' => $form, 'attributes' => $attributes instanceof sfOutputEscaper ? $attributes->getRawValue() : $attributes)) ?]</div>
  49. [?php elseif ($field->isComponent()): ?]
  50. <div class="[?php echo $divClass ?]">[?php include_component('<?php echo $this->getModuleName() ?>', $name, array('<?php echo $this->getModuleName() ?>' => $form->getObject(), 'form' => $form, 'attributes' => $attributes instanceof sfOutputEscaper ? $attributes->getRawValue() : $attributes)) ?]</div>
  51. [?php elseif ($field->getConfig('markdown')): ?]
  52. [?php include_partial("dmAdminGenerator/markdown", array("form" => $form, "field" => $field, "class" => $class, "name" => $name, "label" => $label, "attributes" => $attributes, "help" => $help)); ?]
  53. [?php elseif(isset($form[$name])): ?]
  54. <div data-field-name="[?php echo $name ?]" class="[?php echo $divClass ?][?php $form[$name]->hasError() and print ' errors' ?]">
  55. [?php if ($form[$name]->hasError()): ?]
  56. <div class="error">
  57. <div class="s16 s16_error">[?php echo $form[$name]->renderError() ?]</div>
  58. </div>
  59. [?php endif; ?]
  60. <div class="sf_admin_form_row_inner clearfix">
  61. [?php
  62. echo '<div class="label_wrap">';
  63. echo $form[$name]->renderLabel($label);
  64. if($form[$name]->getWidget() instanceof sfWidgetFormDoctrineChoice && $form[$name]->getWidget()->getOption('multiple'))
  65. {
  66. $newRelationLink = _link(dmDb::table($form[$name]->getWidget()->getOption('model'))->getDmModule()->getSfName() . '/new')->text(__('New'));
  67. if (!$form->isNew()) {
  68. $newRelationLink->param('defaults['.$form->getObject()->getTable()->getRelation(dmString::camelize(substr($name, 0, strlen($name)-5)))->getForeign().']', $form->getObject()->get('id'));
  69. }
  70. echo sprintf('<div class="control selection"><span class="select_all">%s</span><span class="unselect_all">%s</span><span class="see_selected">%s</span><span class="see_unselected">%s</span><span class="see_all">%s</span><span class="create_new">%s</span></div>',
  71. __('Select all', array(), 'dm'), __('Unselect all', array(), 'dm'), __('See selected', array(), 'dm'), __('See unselected', array(), 'dm'), __('See all', array(), 'dm'),
  72. $newRelationLink);
  73. }
  74. $widget = $form[$name]->getWidget();
  75. if($widget instanceof sfWidgetFormDoctrineChoice)
  76. {
  77. $pagination = '';
  78. if($form[$name]->getWidget() instanceof sfWidgetFormDmPaginatedDoctrineChoice){
  79. $pager = $form[$name]->getWidget()->getPager();
  80. $pager->setMaxPerPage($sf_user->getAttribute('<?php echo $this->getModuleName()?>.' . $name . '.max_per_page', 10, 'admin_module'));
  81. $widget->init();
  82. $linkArray = $helper->getRouteArrayForAction('paginateRelation', $form->getObject());
  83. $linkArray['field'] = $name;
  84. ob_start();
  85. include_partial('<?php echo $this->getModuleName()?>/form_field_pagination', array('pager' => $pager, 'form' => $form, 'field' => $name, 'link' => url_for($linkArray)));
  86. $pagination = ob_get_clean();
  87. }
  88. $checkbox_tools='';
  89. if ($widget->getOption('multiple')) {
  90. $checkbox_tools = sprintf('<div class="dm_checkbox_tools"><div class="dm_checkbox_search_filter"><input class="search-box" type="text" title="'.__('Search').'" value="%s"/><span class="clear"><a title="'.__('Clear search').'">X</a></span></div>%s</div>', isset($search) ? $search : '', $pagination);
  91. }
  92. $resizer = '<div class="resize-handler"></div>';
  93. }else{
  94. $checkbox_tools = '';
  95. $resizer = '';
  96. }
  97. echo '</div>';
  98. echo '<div class="content">'.$checkbox_tools.$form[$name]->render($attributes instanceof sfOutputEscaper ? $attributes->getRawValue() : $attributes). $resizer . '</div>';
  99. if ($help)
  100. {
  101. echo '<div class="help">'.__($help, array(), '<?php echo $this->getModule()->getOption('i18n_catalogue')?>').'</div>';
  102. }
  103. elseif($help = $form[$name]->renderHelp())
  104. {
  105. echo '<div class="help">'.$help.'</div>';
  106. }
  107. ?]
  108. </div>
  109. </div>
  110. [?php else: //check if is a media view ?]
  111. <div class="[?php echo $divClass ?]">
  112. [?php
  113. $found = false;
  114. if ('dm_gallery' === $name)
  115. {
  116. $found = true;
  117. include_partial('dmMedia/galleryMedium', array('record' => $form->getObject()));
  118. }
  119. elseif (substr($name, -5) === '_view')
  120. {
  121. $found = true;
  122. include_partial('dmMedia/viewBig', array('object' => $form->getObject()->getDmMediaByColumnName(substr($name, 0, strlen($name)-5))));
  123. }
  124. elseif (substr($name, -5) === '_list')
  125. {
  126. if (!$relation = $form->getObject()->getTable()->getRelationHolder()->get($alias = dmString::camelize(substr($name, 0, strlen($name)-5))))
  127. {
  128. $relation = $form->getObject()->getTable()->getRelationHolder()->get($alias = substr($name, 0, strlen($name)-5));
  129. }
  130. if ($relation)
  131. {
  132. echo '<div class="sf_admin_form_row_inner clearfix">';
  133. echo '<div class="label_wrap">'.__($field->getConfig('label', '', true), array(), '<?php echo $this->getModule()->getOption('i18n_catalogue')?>').'</div>';
  134. echo $sf_context->getServiceContainer()->mergeParameter('related_records_view.options', array(
  135. 'record' => $form->getObject(),
  136. 'alias' => $alias
  137. ))->getService('related_records_view')->render();
  138. echo '</div>';
  139. $found = true;
  140. }
  141. }
  142. if(!$found)
  143. {
  144. if (sfConfig::get('sf_debug'))
  145. {
  146. throw new dmException($name.' is not a valid form field');
  147. }
  148. else
  149. {
  150. echo '?';
  151. }
  152. }
  153. ?]
  154. </div>
  155. [?php endif; ?]