You are here

function fontyourface_ui_apply_by_font_form in @font-your-face 7.2

Provides form to apply selectors to fonts.

1 string reference to 'fontyourface_ui_apply_by_font_form'
fontyourface_ui_apply_page in modules/fontyourface_ui/fontyourface_ui.module
Admin page shows enabled fonts with options to add.

File

modules/fontyourface_ui/fontyourface_ui.module, line 747

Code

function fontyourface_ui_apply_by_font_form($form, &$form_state) {
  $fonts = fontyourface_get_fonts('enabled = 1 OR provider = \'local_fonts\'');
  $form['table'] = array(
    '#prefix' => '<table><tbody><thead><tr><th>' . t('Font') . '</th><th>' . t('Provider') . '</th><th>' . t('CSS Selector') . '</th><th>' . t('Operations') . '</th></tr></thead>',
    '#suffix' => '</tbody></table>',
  );
  foreach ($fonts as $font) {
    $form['table']['row_' . $font->fid] = array(
      '#prefix' => '<tr>',
      '#suffix' => '</tr>',
    );
    $editname = l($font->name, 'admin/appearance/fontyourface/edit/' . $font->fid, array(
      'query' => array(
        'destination' => 'admin/appearance/fontyourface',
      ),
      'attributes' => array(
        'class' => 'edit-link',
      ),
    ));
    $form['table']['row_' . $font->fid]['name'] = array(
      '#markup' => '<td>' . $editname . '</td>',
    );
    $form['table']['row_' . $font->fid]['provider'] = array(
      '#markup' => '<td>' . $font->provider . '</td>',
    );

    // Prepare data for apply.js to create theme CSS instructions.
    // Wrap family name in single quotes if not already wrapped.
    $css_family = $font->css_family[0] == "'" ? check_plain($font->css_family) : "'" . check_plain($font->css_family) . "'";
    $data = 'data-font-family="' . $css_family . '"';
    $data .= !empty($font->css_style) && $font->css_style != 'normal' ? ' data-font-style="' . check_plain($font->css_style) . '"' : '';
    $data .= !empty($font->css_weight) && $font->css_weight != 'normal' && $font->css_weight != '400' ? ' data-font-weight="' . check_plain($font->css_weight) . '"' : '';
    $form['table']['row_' . $font->fid]['css_selector[' . $font->fid . ']'] = array(
      '#prefix' => '<td class="css-selector" ' . $data . '>',
      '#type' => 'textfield',
      '#maxlength' => 1024,
      '#size' => 50,
      '#default_value' => $font->css_selector,
      '#suffix' => '</td>',
    );
    $actionsedit = l(t('Edit'), 'admin/appearance/fontyourface/edit/' . $font->fid, array(
      'query' => array(
        'destination' => 'admin/appearance/fontyourface',
      ),
      'attributes' => array(
        'class' => 'edit-link',
      ),
    ));
    $actions = l(t('Disable'), 'admin/appearance/fontyourface/disable/' . $font->fid, array(
      'query' => array(
        'destination' => 'admin/appearance/fontyourface',
      ),
      'attributes' => array(
        'class' => 'disable-link',
      ),
    ));
    if ($font->provider == 'local_fonts' && !$font->enabled) {
      $actions = l(t('Enable'), 'admin/appearance/fontyourface/enable/' . $font->fid, array(
        'query' => array(
          'destination' => 'admin/appearance/fontyourface',
        ),
        'attributes' => array(
          'class' => 'enable-link',
        ),
      ));
      $actions .= ' - ';
      $actions .= l(t('Delete'), 'admin/appearance/fontyourface/local_fonts/delete/' . $font->fid, array(
        'query' => array(
          'destination' => 'admin/appearance/fontyourface',
        ),
        'attributes' => array(
          'class' => 'disable-link',
        ),
      ));
      $form['table']['row_' . $font->fid]['css_selector[' . $font->fid . ']'] = array(
        '#prefix' => '<td>',
        '#markup' => t('Font disabled'),
        '#suffix' => '</td>',
      );
    }
    $form['table']['row_' . $font->fid]['disable'] = array(
      '#markup' => '<td>' . $actionsedit . " - " . $actions . '</td>',
    );
  }

  // foreach
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save applied CSS selectors'),
  );
  return $form;
}