It seems SilverStripe is unable to show a preview of .ico files. Is this a framework issue or client code issue?
The UploadField is added in SiteConfig
private static $has_one = array(
'Favicon' => 'Image'
);
$fields->addFieldToTab("Root.Main", UploadField::create('Favicon', 'Favicon'));
Related
What I'm looking to do is create a very basic plugin for Wordpress. I've followed countless tutorials and examples, but haven't found anything close to what I'm looking for.
I'm trying to create something simple where it has a link on the admin nav bar, and just shows some static html on the right side of the page. The public wouldn't see anything at all.
This sounds like a simple task, but so far, has been everything but simple. Any help or pointing in the right direction would be appreciated. :)
Create a folder named helloworld in your plugins folder and add a file called helloworld.php. In your PHP file, use a hook to add the link to the admin menu.
<?php
/*
Plugin Name: Hello World
*/
add_action('admin_bar_menu', 'add_navbar_item', 100);
function add_navbar_item($admin_bar){
$admin_bar->add_menu( array(
'id' => 'my-item',
'title' => 'My Item',
'href' => '#',
'meta' => array(
'title' => __('My Item'),
),
));
}
I've run into a very bizarre issue while creating 2 TreeDropdownFields for a DataObject. For some reason, only 1 of the 2 TreeDropdownFields render correctly in the SilverStripe admin. The other doesn't render as a TreeDropdownField at all but just as a label:
Here is the code:
class HomeBanner extends DataObject {
public static $db = array(
'SortOrder' => 'Int',
'Title' => 'Varchar'
);
public static $has_one = array(
'Image' => 'Image',
'SecondaryImage' => 'Image',
'FirstLink' => 'SiteTree',
'SecondLink' => 'SiteTree'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab('Root.Main', 'PageID');
$fields->removeFieldFromTab('Root.Main', 'SortOrder');
$fields->addFieldToTab('Root.Main', new TreeDropdownField('FirstLinkID', 'First Link', 'SiteTree'));
$fields->addFieldToTab('Root.Main', new TreeDropdownField('SecondLinkID', 'Second Link', 'SiteTree'));
return $fields;
}
public static $summary_fields = array(
'ID' => 'ID',
'Title' => 'Title',
'Thumbnail' => 'Thumbnail'
);
public function getThumbnail() {
return $this->Image()->CMSThumbnail();
}
}
Here is what I have tried so far:
running dev/build/?flush=true
running ?flush=all and ?flush=1
logging out and logging back in after the dev/build + flushes
logging into the admin in another browser (I typically use Chrome but
logged into the site's admin on FireFox and saw the same problem)
The error logs report nothing -- they're clear
There are no errors in the console for Chrome's dev tools
Adding a third TreeDropdownField will allow the first 2 to render
properly but the third one will just show a label instead of a
TreeDropdownField
This format works, but doesn't save whatever is selected--it clears your choice as soon as you leave the page. Also, it deletes all that was saved already in the admin unless I remove it. I can't make changes or else the items saved get removed.):
$fields->addFieldToTab('Root.Main', new TreeDropdownField('SecondLink', 'Second Link', 'SiteTree', 'ID'));
Does anyone have any ideas as to why this could be happening? It doesn't seem to make sense that you can't have multiple TreeDropdownFields.
Reposting as this turned out to be the answer:
The name “HomeBanner” suggests to me that there should also be a has_one pointing back to HomePage or similar? The cause of this is probably that SilverStripe is automatically trying to set one of the has_one relations to point back to the page that the banner belongs to.
Similar conflicts can also happen when using code like this:
class Page extends SiteTree {
private static $has_many = [
'Banners' => 'Banner'
];
}
class Banner extends DataObject {
private static $has_one = [
'Page' => 'Page',
'LinkedPage' => 'Page'
];
}
As SilverStripe doesn't know whether it should use PageID or LinkedPageID to auto-populate that side of the has_many relation (GridField will try to automatically assign the correct has_one ID).
In these cases, you can use dot-notation to distinguish between them - you’d change it to $has_many = ['Banners' => 'Banner.Page'];. See https://docs.silverstripe.org/en/3/developer_guides/model/relations/#has-many for more info.
I am trying to create a Drupal module. I've been able to setup the configuration form on the admin section - it runs fine: I can add the component and set configurations and save.
However, nothing appears on the front end of the site. There are no errors. I'm not sure why and, as I am new to Drupal, I'm not sure where to look.
My hook_theme in my .module file looks like:
function gallery_grid_theme($existing, $type, $theme, $path) {
return array(
'gallery_grid' => array(
'template' => 'gallery-grid',
'path' => 'plugins/content_types/gallery_grid/templates',
'type' => 'theme',
'variables' => [],
)
);
}
The .tpl file is intact and has no markup errors.
Would anyone know what file I should be looking at?
EDIT:
I've tried clearing the cache and rebuilding the registry as well as disabling and re-enabling the module, to no affect.
The module is added to a page panel as a component (gear icon, Add Content).
For some reasons this needed an absolute path:
'path' => drupal_get_path('module', 'gallery_grid') . '/plugins/content_types/gallery_grid/templates',
I am trying to migrate content (at this point user accounts specifically) from a legacy site into Drupal 7 using the Drupal Migrate module but for some reason the custom site migration class is not being registered. The only indication that something is wrong is the lack of any output when running drush migrate-status, and the output "No migration groups defined" when visiting http://<drupal_root_url>/admin/content/migrate in a web browser. The migrate, migrate_ui, and pinpics_migration modules have all been enabled via the Drupal 7 admin dashboard. I have tried using drush to clear all caches and register the migration classes, as well as registering the migration classes using the web UI to no avail. drush was run from the folder with the settings.php file /<drupal_root_path>/sites/default/
drush cc all && drush migrate-register && drush migrate-status
I have the following files located in
/<drupal_root_path>/sites/all/modules/custom/pinpics_migration/
pinpics_migration.info
pinpics_migration.migrate.inc
pinpics_migration.module
I have tried placing the file containing the custom migration class implementation pinpics_users.inc in the same directory as the files above, as well as in:
/<drupal_root_path>/includes/
Here are the file contents:
pinpics_migration.info:
<?php
name = "Pinpics Migration"
description = "Module to migrate legacy site to Drupal 7 site"
package = "Migration"
core = 7.x
dependencies[] = migrate
files[] = pinpics_migration.module
files[] = pinpics_users.inc
?>
pinpics_migration.migrate.inc:
<?php
function pinpics_migration_migrate_api() {
$api = array( 'api' => 2 );
return $api;
}
?>
pinpics_migration.module:
<?php
define("SOURCE_DATABASE", "pinpics_db");
?>
pinpics_users.inc: (Stripped of some helper functions, and specific implementation details)
<?php
/// Stripped some helper functions that were used by pinpicsUserMigration::prepareRow() below
class pinpicsUserMigration extends Migration {
public function __construct() {
parent::__construct(MigrateGroup::getInstance('user_migration_group'));
$this->description = t('Migrate pinpics.com users');
$source_fields = array(
'uid' => t('User ID'),
'roles' => t('The set of roles assigned to a user.'),
'password' => t('MD5 hash of User Password'),
'email' => t('User email address'),
'name' => t('Username'),
'created' => t('Timestamp that legacy account was created.'),
'status' => t('The staus of the User account'),
'logintime' => t('Timestamp that the User last logged in.')
);
$query = db_select(SOURCE_DATABASE.'.users', 'u')
->fields('u', array('uid', 'roles', 'password', 'email', 'name', 'created', 'logintime', 'status'))
->condition('status', '0', '=')
->condition('inactive', '0', '=')
->condition('email', '', '<>')
->condition('loginip', '', '<>')
->orderBy('uid', 'ASC');
$this->source = new MigrateSourceSQL($query, $source_fields);
$this->destination = new MigrateDestinationUser(array('md5_passwords' => TRUE));
$this->map = new MigrateSQLMap($this->machineName,
array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'non null' => TRUE,
'description' => 'Legacy Unique User ID',
'alias' => 'u',
)
),
MigrateDestinationUser::getKeySchema()
);
$this->addFieldMapping('uid', 'uid');
$this->addFieldMapping('name', 'name');
$this->addFieldMapping('pass', 'password');
/// Many addFieldMapping() statement stripped out for brevity.
}
public function prepareRow($current_row) {
/// Stripped implementation details for massaging data to prepare for Drupal 7.
return TRUE;
}
}
?>
I am new to Drupal, and have been using the following references to implement the migration.
Drupal 6 to Drupal 7 via Migrate 2
Getting started with Migrate
Has anyone encountered this problem before, or know how to go about finding out what is wrong?
Try these steps:
Visit your sites modules page /admin/modules to trigger rebuilding of cached PHP.
Disable and enable your module to get a new class registered.
I am building a theme with ability to upload custom background images but now I am stuck at a point.
How do I properly add FILE field in drupal form via theme-setting.php and after that how can I get public url to this file in my template files??
In your theme_form_system_theme_settings_alter hook you need to add the following form element:
$form['theme_settings']['background_file'] = array(
'#type' => 'managed_file',
'#title' => t('Background'),
'#required' => FALSE,
'#upload_location' => file_default_scheme() . '://theme/backgrounds/',
'#default_value' => theme_get_setting('background_file'),
'#upload_validators' => array(
'file_validate_extensions' => array('gif png jpg jpeg'),
),
);
This will save the file id to your theme settigns variable 'background_file', notice that i set the upload location to theme/backgrounds, this will be inside your files folder.
Finally you'll get the complete URL to the file with file_create_url:
$fid = theme_get_setting('background_file');
$image_url = file_create_url(file_load($fid)->uri);
Edit:
In your template.php you can add in the theme_preprocess_page hook the variable so all the tpl's can access it, this is how:
function theme_preprocess_page(&$variables, $hook) {
$fid = theme_get_setting('background_file');
$variables['background_url'] = file_create_url(file_load($fid)->uri);
}
Hope this helps! :D